Search code examples
mysqlluamysql-proxy

How to trace MySql queries using MySql-Proxy?


I just downloaded the mysql-proxy and created this script lua (found in Mysql docs):

function read_query(packet)
   if string.byte(packet) == proxy.COM_QUERY then
     print("QUERY: " .. string.sub(packet, 2))
   end
 end

This is the command-line I'm using:

mysql-proxy -P localhost:1234 -b localhost:3306 --proxy-lua-script=profile.lua --plugins=proxy

When I run a simple query (like "select * from table1"), this error is reported: "failed: .\lua-scope.c:241: stat(C:...\profile.lua) failed: No error (0)"

Note: If I run mysql-proxy without lua script, no error occurs.

I need to install something to get mysql-proxy and query tracing working?

My environment is Windows 7 Professional x64.

Sorry the bad english.


Solution

  • The error you're getting is caused by --proxy-lua-script pointing to a file that mysql-proxy can't find. Either you've typed the name in wrong, you've typed the path in wrong, or you are expecting it in your CWD and it's not there. Or actually, looking at the entire error a little more closely, it seems possible that mysql-proxy itself sees the file in CWD itself OK, but one of the underlying modules doesn't like it (possibly because mysql-proxy changes the CWD somehow?)

    Try saving profile.lua to the root of your C: drive and trying different versions of the option like so:

    --proxy-lua-script=c:\profile.lua
    --proxy-lua-script=\profile.lua
    --proxy-lua-script=/profile.lua
    

    One of those would probably work