The slow query log consists of SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined.
The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization.
Here are the steps to enable MySQL slow query log permanently:
Login to server and edit MySQL configuration file
vi /etc/my.cnf
Add the following:
#Slow Query Log #Log file log-slow-queries = /var/log/slow-queries-log #Logs queries longer than 2 sec long_query_time = 2 #Logs queries not using indexes log-queries-not-using-indexes TRUE
Change ownership of the log file /var/log/slow-queries-log to mysql for user and group.
chown mysql.mysql /var/log/slow-queries-log
Restart mysql
/etc/init.d/mysql restart