1

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

Community
  • 1
  • 1
  • are you sure mysql sources are situated at `/usr/include/mysql`? – hjpotter92 Sep 19 '15 at 10:00
  • 1
    I've edited my question and linked the resource where I found this information:http://stackoverflow.com/questions/14604228/mysql-h-file-cant-be-found?lq=1 The top comment suggest that location. –  Sep 19 '15 at 10:01
  • Did you try `find /usr/ -name 'mysql.h'`? – hjpotter92 Sep 19 '15 at 10:07
  • 1
    Yes, I verified it by looking in the folder. Anyway, here is the output of your command: /usr/include/mysql/mysql.h –  Sep 19 '15 at 10:55
  • 1
    For each dependency you can specify three directories in LuaRocks: `XYZ_DIR`, `XYZ_INCDIR`, and `XYZ_LIBDIR`. If the last two are missing, LuaRocks tries to derive them from the first one by appending `/include` or `/lib`, respectively. It seems you wanted `MYSQL_INCDIR` instead of `MYSQL_DIR` in your command line. – siffiejoe Sep 19 '15 at 21:12

4 Answers4

6

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')"))
1

If you want to install it manually:

apt-get install -y libmysqlclient-dev git
luarocks install luasql-mysql MYSQL_INCDIR=/usr/include/mysql
Cr4xy
  • 179
  • 1
  • 8
0

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

AaronDanielson
  • 2,230
  • 28
  • 29
0

I had to use MYSQL_INCDIR

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

Cause it failed with MYSQL_DIR

mirkobrankovic
  • 2,389
  • 1
  • 21
  • 24