Enabling the MySQL general log

Enabling the general query log in MySQL lets you see what mysqld is up to. For example when clients connect or disconnect and any SQL statements that are received from clients. The general log will log queries in the order that it recieves them. Note that this may not be the order in which they are in fact executed. This is contrasts with the binary log where the queries are only written after they are executed but before any locks are released. The general log will also log all statements while the binary log will not log any statements which only select data. Enabling the general log is as simple as editing the my.ini file. On Windows this is normally found at C:\Program Files\MySQL\MySQL Server 5.5. Obviously adjust for your particular version of MySQL.

In order to enable the general query log add the following line to the my.ini file.

    general_log=1

This will now start logging by default to a file located in the data directory named host_name.log. You can adjust the default filename for the general log by adjusting the general_log_file setting in my.ini. If you specify an abolute path this will be used in preference to the data directory.

general_log_file=file_name

Trivially you can adjust whether you log to file, table or both using the log-output setting

log-output=TABLE,FILE

If you have table set then each line of the log file will be added to a MySQL table under the mysql database called general_log. This can be really useful if you want to use the power of MySQL to search through the general log.

Once you've made any of these changes to the my.ini file you will then need to restart the service running MySQL to ensure that the changes are picked up. Alternatively you can adjust any of the settings at runtime with commands similar to this.

SET GLOBAL general_log = 'OFF';

This particular command turns the general log off. Using commands like this means that you can change settings on the fly without having to restart the service which you may obviously not always want to do. Note that when you do come to restart the service all of these runtime settings will be lost.