Log In | Register | October 19, 2019

Share
 

Linux - October 17, 2011

Enable Slow Query Log for MySQL GNU / Linux

In order to enable slow query logs for MySQL on your system you would need to do the following.

1st Step is to edit your my.cnf file which is located in your /etc directory.

vi /etc/my.cnf

Once you have your my.cnf file open, then add the following 4 lines then save and exit the file.
[mysqld]
log-slow-queries
log-slow-queries=/var/log/mysql/slow-queries.log
long_query_time=1

Then create the file slow-queries.log. You can have the file in any spot you wish, as long as you define the path in your my.cnf.

touch /var/log/mysql/slow-queries.log

Change the ownership of the file to be owned by MySQL.

chown mysql.mysql /var/log/mysql/slow-queries.log

Lastly, you will need to restart mysqld for your changes to take place.

service mysqld restart

Now you should have slow query logs enabled catching any MySQL query that took longer then 1 second to process.

Post By: | FavoriteLoadingAdd to favorites

0 Comments

Leave a Comment



Need Help? Ask a Question

Ask anything you want from how to questions to debug. We're here to help.

You Must Be Logged In To Post A Question.

Log In or Register