Thursday, May 9, 2013

Setup MySQL Proxy

So this is just a very simple example of using MySQL Proxy ..

The MySQL Proxy has been in the Alpha stages for what feels like years on end.

MySQL Proxy Documentation :
Whatever is left from the MySQL forge site for MySQL Proxy WIKI can be found here:

Install MySQL Proxy:
Download and unpack from Current Alpha version is mysql-proxy 0.8.3.

Make sure you also have Lua installed

yum install lua-devel lua-static lua

You will then find mysql-proxy in the bin directory.

[root@localhost bin]# ./mysql-proxy --help
  mysql-proxy [OPTION...] - MySQL Proxy

MySQL command options:

First need to make sure you are aware of the out of date documentation.

You might think that adding daemon=true to your configuration file is valid.
It does after all point out how true is the valid for the following option via the documentation.

For example, the following is invalid:


But this is valid:

proxy-skip-profiling = true

However daemon or daemon=true results with the following issue so use daemon=1

./bin/mysql-proxy --defaults-file=mysql_proxy.cnf
(critical) Key file contains key 'daemon' which has value that cannot be interpreted.

The same is true for keepalive=true

./bin/mysql-proxy --defaults-file=mysql_proxy.cnf
(critical) Key file contains key 'keepalive' which has value that cannot be interpreted.

Using the Administration Interface:

The admin.lua file is available under the mysql-proxy directory:
The reporter.lua file can also be placed into the  /lib/mysql-proxy/lua/ directory:

So I end up with the following configuration example

vi mysql_proxy.cnf


admin-address =


proxy-skip-profiling = true
pid-file = /var/run/
log-file = /var/log/mysql-proxy.log
log-level = debug
#proxy-read-only-backend-addresses =

This time it starts....

./bin/mysql-proxy --defaults-file=mysql_proxy.cnf

Tail you log to confirm that proxy is up and running then log into the admin port (3308)

(message) proxy listening on port
# mysql -u root -p -P3308 -h127.0.0.1

Once you are logged in you can start to test it:

# mysql -u root -p -P3308 -h127.0.0.1

show querycounter;
| query_counter |
|          NULL |

SELECT * FROM backends;
| backend_ndx | address        | state | type |
|           1 | | 1     | 1    |

ERROR 1105 (07000): need a resultset + proxy.PROXY_SEND_RESULT ... got something else

Remember always check your logs...

(critical) (read_query) [string "/usr/local/src/MySQL/mysql-proxy/admin.lua"]:152: bad argument #1 to 'pairs' (table expected, got nil)

OK the MySQL Proxy is up...
Now the issues and complains over Lua and why is it part of MySQL-Proxy can begin...