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.
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.
相关文章推荐
- MySQL 慢查询日志(Slow Query Log)
- 使用pt-query-digest分析mysql slow query log
- mysql 慢查询日志(slow_query_log_file)切换
- mysql慢日志 :slow query log 分析数据
- mysql:慢查询日志slow_query_log
- mysql dba系统学习(9)slow query log慢查询日志功能
- MySQL开启慢查询日志slow_query_log
- 使用pt-query-digest分析mysql slow query log
- 开启mysql查询日志 mysql——slow query log
- mysql慢查询Slow Query Log和未使用索引(Not Using Indexes)查询配置和使用
- MySQL日志(一):slow query log
- 用mysqldumpslow分析mysql的slow query log
- mysql慢查询Slow Query Log和未使用索引(Not Using Indexes)查询配置和使用
- MySQL 慢查询日志(Slow Query Log)
- 用mysqldumpslow分析mysql的slow query log
- mysql5.6.10关于慢查询的设置slow-query-log
- mysql 5.7 解决 set global slow_query_log=on;报错
- MySQL错误日志(error log),二进制日志(binlog),慢查询日志(slow query log),查询日志(general log),重写日志(redo log)
- 用mysqldumpslow分析mysql的slow query log