Question

For debug purposes, I want to log SQL errors and warnings messages returned by MySQL, and corresponding queries, at server-level.

I've found two useful Lua scripts :

https://github.com/koopa/mysql-proxy-log-error-queries/blob/master/mysql-proxy-log-error-queries.lua https://github.com/patrickallaert/MySQL-Proxy-scripts-for-devs (debug.lua)

which allow to log errors with MySQL Proxy. But I'm still looking for a way to log warnings. I'm not confident with mysql-proxy LUA-scripting. Can someone indicate me how to do this ?

This question : Log warnings into a table seems to be close, but unfortunately the provided link is dead and I can not find the content.

Was it helpful?

Solution

I finally examined the subject in studying literature and developed the Lua script that suits me.

The script I mentioned first (https://github.com/koopa/mysql-proxy-log-error-queries/blob/master/mysql-proxy-log-error-queries.lua) was a good starting point, but :

  • It only logs errors and not warnings. Originally it manages an 'error flag' which is set to true if the client's query returns an error. I changed that in order to log every query for which SHOW WARNINGS returns something (Errors, Warnings or Notes).

  • It inserted errors log lines into a table. It could be nice but can be quite confusing for the client, because inserting the log line clears the messages shown by 'show warnings' query. There's probably a way to fix that, opening a new session or connexion... but I choosed to log events into a simple text file. Secondarily, the insert query in the original script can generate a syntax error because of the simple quotes ' possibly contained in the error message or original query.

There is a point at which we must be careful when logging all warnings : all queries don't clear the warnings/notes queue. So SHOW WARNINGS can return a resultset generated by a previous query after a non-warning-generating query. To fix that, I use a dirty method : after detecting a query, I inject a bad query for which I know it will generate an error message; after what I ignore this error message. It's a way to "clear" warnings and notes...

OTHER TIPS

You can download this script and specify while configuring MySQL-proxy. Command line options are listed here: MySQL-proxy-configuration

Typical MySQL-proxy configuration will look like this in your case:

$ mysql-proxy --proxy-backend-addresses=192.168.x.x:3305 --proxy-address=192.168.y.y:4045 --proxy-lua-script=mysql-proxy-log-error-queries.lua

I guess you might have to modify this script to connect to MySQL-proxy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top