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

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';

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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github