主要参考:http://www.boll.me/archives/614
luasql安装, 在终端通过yum命令安装:
yum -y install lua-sql
接下来写个测试的lua脚本文件(通过lua连接mysql数据库),如:
#!/usr/bin/lua local luasql = require "luasql.mysql"
local env = assert(luasql.mysql())
local con = assert(env:connect("mysql", "root", "", "192.168.1.90", ))
local cur = assert(con:execute("show databases"))
local row = cur:fetch ({}, "a") while row do
print(row.Database)
row = cur:fetch (row, "a")
end cur:close()
con:close()
env:close()
运行结果:
[zcm@vm-fedora20 lua]$ ./mysql.lua
information_schema
mysql
performance_schema
sakila
test
world