Wednesday, August 28, 2013

Enable log slow query mysql

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.cnfPlain Text
Once you have your my.cnf file open, then add the following 4 lines then save and exit the file.
Plain Text
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.logPlain Text
Change the ownership of the file to be owned by MySQL.
chown mysql.mysql /var/log/mysql/slow-queries.logPlain Text
Lastly, you will need to restart mysqld for your changes to take place.
service mysqld restartPlain Text

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