The MySQL general query log can be handy for getting a more thorough overview of what is going on behind the scenes of your app. particularly if your database logic is abstracted out of the way and you want to see whats going on. The MySQL documentation says the following on the MySQL general query log:
The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.
Wise words indeed.
I wanted to enable it in MAMP so I hit the internet. Now this may well be common knowledge for all I know but when I did a google for it I came across a few articles that were out of date. So here’s how I ended up doing it in the end:
- Open up /Applications/MAMP/bin/startMysql.sh in your editor of choice
- Before the ampersand at the end of the line that kicks off mysqld_safe add the following:
it should end up looking something like this:
/Applications/MAMP/Library/bin/mysqld_safe --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lower_case_table_names=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysql_error_log --log=/Applications/MAMP/logs/mysql_general_log &
- Save, obviously
- Stop and start the servers through the MAMP control panel thingy
- Test and celebrate. You could maybe do something like
tail -f /Applications/MAMP/logs/mysql_general_log
so that lots of stuff scrolls past so that you feel like you’re hacking in a movie, Thats what I do.
Be warned however, this has only been enabled on my developing machine for a couple of days and already it is at nearly 800k. It might be wise to clear it once in a while via either a cron job or something similar. I guess log rotate may also be an option.