Posted on under MySQL by Owen Conti.
The general log records every query that the MySQL database processes, with the parameters visible. This means you are able to see the values used in a bound query.
There are two ways to enable the MySQL general log:
To enable the general log via the configuration file, add the following to your configuration file (example path is
/etc/my.cnf
):
1// my.cnf2[mysqld]3general_log = 14log_output = 'table'
You must restart the MySQL server after editing the configuration file.
To enable the general log via a global query, you can run this query:
1SET global general_log = 1;
Now that the general log is enabled, you have a couple options on where the log is written to. By default, it’s written to a log file located at:
/var/log/mysql/mysql.log
However, when I enable the general log for debugging, I often have the output written to a table, so I can query it easily. To write the output to a table, you can run this global query:
1SET global log_output = 'table';
You can query the general log table via:
1SELECT * FROM mysql.general_log;
The results returned can be filtered, sorted, etc:
1SELECT * FROM mysql.general_log ORDER BY event_time DESC LIMIT 100;
Hopefully you found this article useful! If you did, share it on X!
Found an issue with the article? Submit your edits against the repository.