2

I wanted to install luasql.mysql with luarocks, and I've ran into a problem. Even though the packages were installed providing mysql.h, luarocks couldn't find it. I solved it eventually:

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

Now, all prerequisites should be met, to use luasql.mysql, but I'm getting an error:

> require "luasql.mysql"
stdin:1: module 'luasql.mysql' not found:
    no field package.preload['luasql.mysql']
    no file '/usr/local/share/lua/5.2/luasql/mysql.lua'
    no file '/usr/local/share/lua/5.2/luasql/mysql/init.lua'
    no file '/usr/local/lib/lua/5.2/luasql/mysql.lua'
    no file '/usr/local/lib/lua/5.2/luasql/mysql/init.lua'
    no file './luasql/mysql.lua'
    no file '/usr/share/lua/5.2/luasql/mysql.lua'
    no file '/usr/share/lua/5.2/luasql/mysql/init.lua'
    no file './luasql/mysql.lua'
    no file '/usr/local/lib/lua/5.2/luasql/mysql.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.2/luasql/mysql.so'
    no file '/usr/lib/lua/5.2/luasql/mysql.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './luasql/mysql.so'
    no file '/usr/local/lib/lua/5.2/luasql.so'
    no file '/usr/lib/x86_64-linux-gnu/lua/5.2/luasql.so'
    no file '/usr/lib/lua/5.2/luasql.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './luasql.so'
stack traceback:
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: in ?

Now, in that list, there is no /usr/local/lib/luarocks/rocks/ or anything like that. Also, I can't seem to find a mysql.lua.

According to luarocks, luasql-mysql is installed correctly, though:

% luarocks list

Installed rocks:
----------------

luasql-mysql
   2.3.0-1 (installed) - /usr/local/lib/luarocks/rocks

I believe I did something wrong, but I have no idea where. Also, it seems Lua is quite obscure when it comes to installing additional packages...

polemon
  • 11,133
  • 11
  • 69
  • 111
  • Can anyone know how to configure MariaDB with Lua. I have tried to luarocks install luasql.mysql, its says 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 I have tried to locate the mysql.h, but i cant able to find. – Kirubaharan Sep 05 '14 at 20:16

2 Answers2

2

OK, I solved it, and it was quite a stupid mistake:

luasql.mysql is only available for Lua 5.1, not Lua 5.2, which I use by default. Running lua5.1 solves the issue:

% lua5.1       
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require "luasql.mysql"
>

...and all is good.

Sorry to have created a confusion...

polemon
  • 11,133
  • 11
  • 69
  • 111
1

Have you tried to set lua.package_cpath or lua.package_path in your LUA script?

Or set LUA_CPATH and LUA_PATH environment variable?

i.e export LUA_PATH='/usr/local/lib/luarocks/?.so'; lua ./XX.lua

daisy
  • 53,527
  • 78
  • 236
  • 383