Luasql mysql安装错误解决

首先需要安装LuaRocks:

wget http://luarocks.org/releases/luarocks-2.2.1.tar.gz
tar zxpf luarocks-2.2.1.tar.gz
cd luarocks-2.2.1
./configure; sudo make bootstrap
sudo luarocks install luasocket

接着安装luasql-mysql:

luarocks install luasql-mysql

会出现以下报错:

Error: Could not find header file for MYSQL
  No file mysql.h in /usr/local/include
  No file mysql.h in /usr/include
You may have to install MYSQL in your system and/or pass MYSQL_DIR or MYSQL_INCDIR to the luarocks command.
Example: luarocks install luasql-mysql MYSQL_DIR=/usr/local

解决方法,使用如下命令:

sudo luarocks install luasql-mysql MYSQL_INCDIR=/usr/local/mysql/include

如果报以下错误:

export MACOSX_DEPLOYMENT_TARGET=10.8; gcc -bundle -undefined dynamic_lookup -all_load -o luasql/mysql.so -L/usr/local/lib src/luasql.o src/ls_mysql.o -L/usr/local/lib -Wl,-rpath,/usr/local/lib: -lmysqlclient
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Error: Build error: Failed compiling module luasql/mysql.so

可以修改上面命令为:

sudo luarocks install luasql-mysql MYSQL_INCDIR=/usr/local/mysql/include MYSQL_LIBDIR=/usr/local/mysql/lib

这样luasql-mysql就安装成功了,当你尝试链接数据库时如果报以下错误:

lua: error loading module 'luasql.mysql' from file '/usr/local/lib/lua/5.3/luasql/mysql.so':
	dlopen(/usr/local/lib/lua/5.3/luasql/mysql.so, 6): Library not loaded: @rpath/libmysqlclient.21.dylib
  Referenced from: /usr/local/lib/lua/5.3/luasql/mysql.so
  Reason: image not found

可以使用下面命令来解决:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib

你可能感兴趣的:(Lua)