您的位置:首页 > 产品设计 > UI/UE

MySQL slow query log

2010-07-29 09:26 246 查看
The MySQL slow query log enables you to log all queries that take longer than a specified number of seconds to execute. This should help identify any queries that are not performing sufficiently.

All that is required is two additional lines in the MySQL configuration file “my.cnf” in the [mysqld] section.

[mysqld]

log-slow-queries = /var/log/mysql-slow.log

long_query_time = 4

The above configuration will log any queries taking longer than 4 seconds to execute in to the specified log file.

MySQL appears to require that the specified log file exists otherwise the logging is disabled and the error below

appears in the MySQL log. (Or it may be that it didn’t have permissions to create the file. I haven’t investigated).

081013 14:55:37 [ERROR] Could not use /var/log/mysql-slow.log for logging (error 13). Turning logging off for
the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server
and restart it.

To create the log file I did the following:

touch /var/log/mysql-slow.log

chown mysql.mysql /var/log/mysql-slow.log

chmod o-r /var/log/mysql-slow.log

The third command is probably unnecessary, but it meant that the permissions matched the mysqld.log

in the same directory.

Once this is done MySQL needs to be restarted to start the query logging:

service mysql restart

This entry was posted on Monday, October 13th, 2008 at 5:34 pm and is filed under MySQL. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: