相关说明:
Lua最近在Nginx的web服务器上挺火的, 它的高效让更多开发喜欢上它, 本文讲述Lua与LuaSQL的安装. 在上几篇mysql-proxy的安装中有提到和操作过.
操作系统: Linux CentOS 相关软件: Lua LuaSQL
操作过程:
安装编译所需要的依赖包
|
yum-yinstall makegcc gcc-c++autoconf pkgconfig libtool mysql-devel ncurses ncurses-devel git
|
编译安装readline
|
cd
wget ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz
tar-xzvf readline-6.2.tar.gz
cdreadline-6.2
|
|
./configure
make
makeinstall
|
编译安装lua
|
cd
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar-xzvf lua-5.1.4.tar.gz
cdlua-5.1.4
|
|
#指定安装位置
sed-i's#^INSTALL_TOP=.*#INSTALL_TOP= /usr/local/lua-5.1.4#gi'./Makefile
#如果系统为64位请执行下面这条命令
#sed -i 's#^CFLAGS=.*#CFLAGS= -O2 -fPIC -Wall $(MYCFLAGS)#gi' ./src/Makefile
makelinux
makeinstall
|
|
mkdir/usr/local/lua-5.1.4/lib/pkgconfig
cp./etc/lua.pc/usr/local/lua-5.1.4/lib/pkgconfig
sed-i's#^prefix=.*#prefix= /usr/local/lua-5.1.4#gi'/usr/local/lua-5.1.4/lib/pkgconfig/lua.pc
|
编译安装LuaSQL
|
cd~
git clonehttps://github.com/keplerproject/luasql.git
cd luasql
sed-i's#^PREFIX =.*#PREFIX =/usr/local/lua-5.1.4#gi'./config
make
makeinstall
|
使用Lua连接Mysql
|
export LUA_CPATH="/usr/local/lua-5.1.4/lib/lua/5.1/?.so;"
|
编辑mysql.lua, 加入如下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
|
localluasql=require"luasql.mysql"
localenv=assert(luasql.mysql())
localcon=assert(env:connect("mysql","root","","localhost",3306))
localcur=assert(con:execute("show databases"))
localrow=cur:fetch({},"a")
whilerow do
print(row.Database)
row=cur:fetch(row,"a")
end
cur:close()
con:close()
env:close()
|
执行:
|
[root@localhost~]# /usr/local/lua-5.1.4/bin/lua mysql.lua
information_schema
mysql
test
[root@localhost~]#
|
相关链接:
Lua: http://www.lua.org/ LuaSQL: http://www.keplerproject.org/luasql/
|
请发表评论