HostOnNet Blog

How to enable MySQL slow query log

Looking for Linux Server Admin or WordPress Expert? We can help.


The slow query log consists of SQL statements that took more than long_query_time seconds to execute and required at leastmin_examined_row_limit rows to be examined.

It is very useful in troubleshooting bad queries.

To edit a file, first make a back-up.

cp /etc/my.cnf /etc/my.cnf.old

Then Now open it in vi:

vi /etc/my.cnf

Add the following line to enable the slow query log:


After that, do the following commands to create the file with the right ownership and file permissions:

vi /var/lib/mysql/slow.log
chmod 660 /var/lib/mysql/slow.log
chown mysql:mysql /var/lib/mysql/slow.log

Once you are done, restart mysql.

About Annie

I've been working in Technical Section for over 10 years in a wide range of tech jobs from Tech Support to Software Testing. I started writing blog for my future reference and useful for all.
Posted in MySQL

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.