How to enable MySQL Query Log?

Better Stack Team
Updated on November 23, 2022

MySQL query log stores the history of executed queries. This history is stored in a log file. On busy servers, this file ca grow very large.

To enable the query log, put the following line into /etc/my.cnf file in the [mysqld] section:

general_log_file = /path/to/query.log
general_log      = 1
Copied!

Alternatively, you can do this at runtime by running the following MySQL commands:

SET GLOBAL log_output = "FILE";
SET GLOBAL general_log_file = "/path/to/your/logfile.log";
SET GLOBAL general_log = 'ON';
Copied!

Don’t forget to replace the "/path/to/your/logfile.log" with the path to the actual log file you wish to store the logs.

Then you can see the logs in the /path/to/your/logfile.log file.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack