Why
There are situations where you want to quickly enable query logging on a MySQL Database or trouble shoot queries hitting the Database server in real-time. Yes, you can enable the DB query log and there are other options available, however the script below has helped me in many cases as it is non intrusive and does not require changing the DB server, state or configuration in any way.
Limitations
The following only works if the DB traffic is not encrypted (no SSL/TLS transport enabled). Also this needs to be run directly on the DB server host (as root / admin). Please also be aware that this should be done on servers and data you own only.
Script
The output of this script is similar to this:
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
You can obviously also limit the filter to certain queries only, run the capture for a few minutes and analyse queries based on occurrence etc.
Replay
I have worked on very high throughput MySQL servers and there can be situations where a simple load test based on inserts or just loading and timing a DB dump is not sufficient in order to judge performance of a newly built system.
Yes, you can enable replication, however this may mean downtime or configuration changes and replication does not replicate any search queries (and batches updates).
The script above is also great to replay existing traffic on a new cluster by just piping the output to a mysql client connected to the second DB server.
Conclusion
Sometimes the easiest option is the best and I hope this post helps somebody in the future.
Comments
Post a Comment