log mysql erroneous queries into a predefined table
Latest commit 874933d Apr 27, 2012 @koopa updated readme
Failed to load latest commit information.
README.md updated readme Apr 27, 2012
mysql-proxy-log-error-queries.lua updated readme Apr 27, 2012



This is a mysql proxy lua script to log erroneous queries to a predefined table


mysql-proxy >= 0.8.2


Create the following table:

CREATE TABLE `somedb`.`mysql_error` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `date` datetime NOT NULL,
    `err_num` smallint(6) NOT NULL,
    `err_type` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
    `err_message` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
    `problem_query` varchar(8000) COLLATE utf8_unicode_ci NOT NULL,
    `conn_id` int(11) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

Change somedb.mysql_error to match your log destination

Also adjust this in the lua script.

Edit the if condition in read_query to match your preferences.

By default, only queries of the user "someuser" will be logged.


  1. >v0.8.2

    /path/to/mysql-proxy --proxy-lua-script=/path/to/mysql-proxy-log-error-queries.lua

  2. >v0.9

    /path/to/mysql-proxy --proxy-lua-script=/path/to/mysql-proxy-log-error-queries.lua --plugins=proxy

By default, mysql-proxy listens on :4040.

NB: By default the hostname in the script will always be set to 'localhost' since you are connecting over the proxy and the proxy connects locally!

To start a connection from the shell to test, use:

mysql -u username -p --host= --port=4040

When using a remote proxy, simply replace with the correct remote address.