mysql slow log activate

Posts regarding the MySQL database server
Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

mysql slow log activate

Post by mister_v »

Hi,

I want to activate mysq slow logs.
To see what queries are slow to respond (and how to improve them)

I thought it was just too comment a line out in /etc/mysql/my.cnf
But I can't find it.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: mysql slow log activate

Post by chris »

You need too add the following 2 lines in /etc/mysql/my.cnf

Code: Select all

log_slow_queries = 1; 
slow_query_log_file = /var/log/mysql/mysql_slow.log
And restart mysqld, so it can read the new config file.

Code: Select all

/etc/init.d/mysql restart
By default a query is slow if it takes more then 10 seconds to execute,
but you can change this by adding the following line:

Code: Select all

long_query_time = 12
now it is 12 seconds :-)

You probably also want to add the new logfile to logrotate,
so it doesn't get too big:
The should already be a file for mysql:
/etc/logrotate.d/mysql

Just add the new file
/var/log/mysql/mysql.err /var/log/mysql/mysql.log /var/log/mysql/mysqld.err /var/log/mysql/mysql_slow.log {
Post Reply