Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

   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...

share|improve this question
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 5 '14 at 20:16
up vote 2 down vote accepted

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...

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.