在Ubuntu上安装luaSQL

TL;DR: 你可以跳转到这里。我试图使用luarocks安装程序,但是apt-get安装程序没有遇到问题。

我在Ubuntu上安装luaSQL时遇到了问题。我需要它来运行一个使用luasql = require“luasql.mysql”的脚本。我按照可以在此处找到的官方文档进行了操作:http://keplerproject.github.io/luasql/doc/us/

我试过的(也是官方文档建议的):

sudo luarocks install luasql-mysql

输出结果为:

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

所以我首先需要获取mysql.h文件。通过一些搜索我找到了这个

sudo apt-get update sudo apt-get install libmysqlclient-dev

所以我再次使用了我的第一条命令,但加上了mysql.h文件的位置:

sudo luarocks install luasql-mysql MYSQL_DIR=/usr/include/mysql

然后它给了我与一开始相同的错误。有人知道在Ubuntu机器上安装luaSQL的正确指令吗?或者可以指引我正确的方向吗?

我的系统:

描述:Ubuntu 14.04.2 LTS

版本:14.04

代号:trusty

点赞
用户88888888
用户88888888

安装 LuaSQL:

apt-get install lua-sql-mysql

感谢来自lua-support irc聊天室的用户“TsT”的贡献:聊天记录可以在此找到:https://botbot.me/freenode/lua-support/msg/50072546/

您可以使用以下测试脚本:

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')"))
2015-09-19 11:19:14
用户1504367
用户1504367

将下面翻译成中文并且保留原本的 markdown 格式,

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`

apt 安装程序无法为我完成。

我通过修改配置文件,从 Github 上(keplerproject/luasql)安装成功。在配置文件中,Lua 5.2 被硬编码,但我的运行环境是 5.1。

在配置文件中,将 LUA_SYS_VER ?= 5.2 替换为 LUA_SYS_VER ?= 5.1

2016-07-22 19:29:24
用户2048620
用户2048620

我不得不使用 MYSQL_INCDIR

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

因为 MYSQL_DIR 失败了。

2016-11-22 12:24:40
用户4904569
用户4904569

如果您想手动安装:

apt-get install -y libmysqlclient-dev git
luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql
2017-05-19 12:33:39