问题
TL;DR: You can skip to here. I was trying to use luarocks installer, but the apt-get installer did it without problems.
I am experiencing issues when installing luaSQL on Ubuntu. I need it for a script that uses luasql = require "luasql.mysql"
. I followed the official documentation which can be found here: http://keplerproject.github.io/luasql/doc/us/
What I've tried (and what was suggested by the official documentation):
sudo luarocks install luasql-mysql
gave me the following output:
Error: Could not find expected file mysql.h for MYSQL --
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
So I first had to get the mysql.h file. After some googling I found this:
sudo apt-get update
sudo apt-get install libmysqlclient-dev
So I tried my first command again, but with the location of the mysql.h file as parameter:
sudo luarocks install luasql-mysql MYSQL_DIR=/usr/include/mysql
And it gave me the same error as in the beginning. Does anyone know the right instructions for installing luaSQL on an Ubuntu machine? Or can point me in the right direction?
My system:
Description: Ubuntu 14.04.2 LTS
Release: 14.04
Codename: trusty
回答1:
to install LuaSQL:
apt-get install lua-sql-mysql
Credits to user 'TsT' from the irc chat of lua-support: the chatlog can be found here: https://botbot.me/freenode/lua-support/msg/50072546/
A test script you can use:
luasql = require "luasql.mysql"
env = assert (luasql.mysql())
con = assert (env:connect("dbname","username","password","host.com"))
cur = assert (con:execute("INSERT INTO `table`(`col_int`,`col_varchar`) VALUES (9,'Hi')"))
回答2:
If you want to install it manually:
apt-get install -y libmysqlclient-dev git
luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql
回答3:
The apt installer didn't do it for me.
I was able to install it from source on github (keplerproject/luasql) by modifying the config file. Lua 5.2 was hard-coded in the config file, but I'm running 5.1.
In the config file, replace LUA_SYS_VER ?= 5.2
with LUA_SYS_VER ?= 5.1
回答4:
I had to use MYSQL_INCDIR
sudo luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql
Cause it failed with MYSQL_DIR
来源:https://stackoverflow.com/questions/32666803/install-luasql-on-ubuntu