我的 mysql 服务器配置了 long_query_time = 2
,但我仍然看到慢速查询日志中报告的这些查询看起来很快:
# Time: 120730 5:06:41
# User@Host: <user> @ <Host> [<IP>]
# Query_time: 0.000412 Lock_time: 0.000060 Rows_sent: 5 Rows_examined: 5
SET timestamp=1343639201;
SELECT album_id FROM `TB_albums` where album_id!='res_4fe4333271bda7.42833845' and deleted is NULL order by `created_time` desc limit 5;
如您所见,Query_time: 0.000412 Lock_time: 0.000060 似乎远低于 2 秒
您知道为什么会报告这些“快速”查询吗?
最佳答案
MySQL也会记录不使用索引的查询
my.cnf中的选项log-queries-not-using-indexes
用于控制这。我的已关闭(通过注释掉),正如您从 my.cnf 的这段代码中看到的
# Here you can see queries with especially long duration
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
#log-queries-not-using-indexes
如果您无权访问 my.cnf,可以使用 SQL 检查
mysql> show variables like 'log_queries_not_using_indexes';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF |
+-------------------------------+-------+
1 row in set (0.00 sec)
希望有帮助!
克里斯
关于mysql - 为什么mysql慢日志会报告这些非慢查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11718462/