Slow queries log for MySQL

To enable slow query log, it is have to add one line into my.cnf.
I have MySQL installation on a Centos server.
It is MySQL 5.0.22 i686.
Let’s go through the details of setting of it.
Open my.cnf which is located at /etc/
add following under mysqld section.

log-slow-queries = /var/log/mysql/mysql-slow.log
long_query_time = 5
log-queries-not-using-indexes

The key point is to manually create the mysql-slow.log file.

cd /var/log
mkdir mysql
touch mysql-slow.log
chmod mysql.mysql -R /var/log/mysql

Last step is to restart mysql server.


After minutes, I saw some records in this log file.
The next question is how to analyse the slow queries log and optimize the program of MySQL.

4 Comments

  1. Thanks for the tutorial, however, this tutorial is full of typos.

    After mkdir mysql, you should either cd to the directory, or in the next step, include the directory in the touch statement. Lastly, chmod should be chown, and these days, it’s good form to use the : instead of . between the username and group.

  2. Thanks for the tutorial, however, this tutorial is full of typos.

    After mkdir mysql, you should either cd to the directory, or in the next step, include the directory in the touch statement. Lastly, chmod should be chown, and these days, it’s good form to use the : instead of . between the username and group.

  3. Hello,
    Great post, but i think that the “chmod mysql.mysql -R /var/log/mysql” should be: “chown mysql.mysql -R /var/log/mysql”
    Happy debuging

Leave a Reply

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