Logging MySQL Queries in Ubuntu

It can be a really handy debugging tool to see exactly what the database is doing sometimes. To do that on Ubuntu 12.04 Server and probably a lot of other linux distros, do this:

Open /etc/mysql/my.cnf

Find these lines:

[bash]# general_log_file = /var/log/mysql/mysql.log
# general_log = 1[/bash]

and uncomment them. Save it and restart mysql:

[bash]sudo /etc/init.d/mysql restart[/bash]

Now tail the log file (you may need root permissions for this):

[bash]sudo tail -f /var/log/mysql/mysql.log[/bash]

Remember not to do this on a production server, as it will majorly slow things down and create some huge log files! Not the dream.