mysql - 为什么mysql慢日志会报告这些非慢查询

标签 mysql mysql-slow-query-log

我的 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/

相关文章:

mysql - 使用 order by 而不改变组的顺序

mysql - 在大型 MySQL InnoDB 表上,完整计数查询真的这么慢吗?

Mysql LEFT JOIN 很慢

MySQL 多个 CHAR_LENGTH()

python - SQLAlchemy:如何使用 SQLAlchemy 更改 MySQL 服务器系统变量?

mysql对小数据集的慢查询

mysql - 是什么让这个查询如此缓慢? (MySQL 5.6.36)

mysql 'slow queries log' 返回检查的大量行但解释似乎没问题

mysql - 如何启动mysql2服务器?

mysql - 如何使用 INSERT INTO 多次选择插入?