Thumbnail image

Enable Query Log Mysql

Wed, Nov 23, 2022 One-minute read

Hello people, this time I’ll use this blog post a a placeholder for a snippet that is useful when working with My SQL and specially if you’re having trouble understanding behaviours on your database.

Enable Query Log Mysql

There are a couple of options when you want to enable query log on your database, the first one is to use the following configuration:

For MySQL 5.1.28 and older, edit the /etc/my.cnf file and in the [mysqld] section add the following line:

log_output = /path/to/file.log

Source

For mysql 5.1.29 and newer, edit the /etc/my.cnf file and in the [mysqld] section add the following line:

general_log = 1
general_log_file = /path/to/file.log

And finally, restart the MySQL server:

sudo service mysql restart

Alternatively if you cannot restart the server, you can use the following commands:

SET GLOBAL general_log = 1;
SET global log_output = 'table';

Then to see the log, you can use the following command:

SELECT * FROM mysql.general_log;

After your debugging has finished, you can turn off the query log by using the following command:

SET GLOBAL general_log = 0;

And truncate the table by using the following command:

TRUNCATE TABLE mysql.general_log;

I hope this helps you to debug your database.

Cheers!