Getting LuaSocket to Work with MySQL Proxy

I’ve seen some interest in trying to get LuaSocket working with MySQL Proxy, and most of those interested have run into issues getting this set up, so I want to provide a brief walk-through on how to get this set-up and working properly.

Note I tested this on Windows, so use .so instead of .dll on *nix systems.

1. Download LuaSocket (contains lua/ and lib/ directories)

2. Copy contents of ‘lua/’ into the following directory:

C:Program FilesMySQLmysql-proxy-0.8.0libmysql-proxylua

3. Copy contents of ‘lib/’ into the following directory:

C:Program FilesMySQLmysql-proxy-0.8.0bin

4. In step #3, you should have copied a ‘socket/’ and ‘mime/’ directories into bin/. Rename the directory named “socket” to “lua-socket”. This will get you past one set of errors.

5. Next, in the C:Program FilesMySQLmysql-proxy-0.8.0bin, there is a file named lua51.dll. If you try to run it now, you’ll get an error saying “lua5.1.dll was not found”. So make a *copy* of “lua51.dll” and rename it “lua5.1.dll” (in the same directory).

6. Invoke your proxy script with the correct –lua-cpath and –lua-path options (below is correct relative to my basedir and with regards to where I copied the contents of the LuaSocket):

C:Program FilesMySQLmysql-proxy-0.8.0bin>mysql-proxy.exe --proxy-lua-script=show-vars.lua --lua-cpath=!\lua-?.dll --lua-path=!\..\lib\mysql-proxy\lua\?.lua;!\..\lib\mysql-proxy\lua\socket\?.lua

Proxy should start up fine with the script, it works, and you can access the socket functions within your own lua script.

For instance, my proxy basedir, which is also where my script is located, is:

C:Program FilesMySQLmysql-proxy-0.8.0

show-vars.lua is the name of my lua script.

In it, I have the following 2 lines:

socket = require("socket") 

And when I start up the script, and connect to my instance, it outputs the following:

LuaSocket 2.0.1

2 thoughts on “Getting LuaSocket to Work with MySQL Proxy”

  1. Just used your trick successfully in a mysql-proxy 0.8.2 under windows 2003 Server 32bits

    Had a hard time finding the binaries for luasocket and finally found them here :

    The other version I found there didn’t work (an import error on the dll was triggered)

    Thanks to that, I implemented a SYSLOG (rfc3164) logging capability for mysql-proxy under Windows : logging user connecting to the proxy, loggin their query, and logging the connection failures.

    Will post it on my blog as soon as possible with lua code and your post in french 😉

Comments are closed.