Reputation: 2731
How to write script in python to trace queries with MySQL Proxy. I have tried to get the information about this but I could not find any thing regarding python,please help me out any body to write a script in python for tacking queries with mysql proxy. And I would like to clarify about working and usage of mysql proxy.
Upvotes: 2
Views: 1934
Reputation: 1324
There is mysql-proxy-python. It doesn't compile against the mysql-proxy version my Ubuntu ships.
After configuring mysql-proxy-python like this ./configure --prefix=/var/tmp/mysqlproxy --with-python=python2.7 --with-gnu-ld --with-mysql-proxy-src=/var/tmp/mysql-proxy-0.8.5/
, I needed to change at least this in config.h:
/* make sure the off_t is 32bit */
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 32
#endif
#define HAVE_ULONG
Then I could run env PYTHONPATH=/var/tmp/mysql-proxy-python/lib/ mysql-proxy --plugin-dir=/var/tmp/mysqlproxy/lib/mysql-proxy/plugins --plugins=pyproxy --pyproxy-backend-addresses=127.0.1:3306 --pyproxy-python-script=/var/tmp/mysql-proxy-python/examples/rewrite.py
.
after a make
and make install
I could connect to the proxy like this mysql --host=127.1 --user=root --password=root --port 2046 mysql
. Note the port, which I found through netstat -tulpen
.
Upvotes: 1
Reputation: 23
How to write script in python to trace queries with MySQL Proxy.
You can download script from https://gist.github.com/simonw/1039751, and save it to file monitor.lua then run proxy:
mysql-proxy --proxy-lua-script=monitor.lua
Then you can write python script and analyze all proxied queries inside file.
By default script output will be flushed into mysql.log, or you can change it directly in the LUA script (monitor.lua).
Mysql-proxy supports only LUA scripting to build plugins, so if you want to affect some specific queries you need to know lua, or found most applicable script for you exact situation.
Upvotes: 0