Page 1 of 1

mysql slow log activate

Posted: Mon Jan 12, 2015 8:40 pm
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.

Re: mysql slow log activate

Posted: Mon Jan 12, 2015 8:52 pm
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 {