mysql 5.6 设置long_query_time的值无效的原因
时间:2022-03-14 01:31
问题:
用网上找的开启慢查询日志的方法:
在/etc/my.cnf中添加
long_query_time=1 slow_query_log log_queries_not_using_indexes=1
然后再重启mysql。
慢查询日志确实开起来了,用select sleep(0.5),select sleep(1)来测试long_query_time的设置是生效的。但是在实际使用中在慢查询日志文件中出现了很多查询时间在小于1s的记录。
原因:
一、在mysql5.6英文手册的“5.2.5 The Slow Query Log”中说慢查询记录的条件:
The query must either not be an administrative statement, or must be enabled.
The query must have taken at least seconds, or must be enabled and the query used no indexes for row lookups.
The query must have examined at least rows.
The query must not be suppressed according to the setting.
粗略地翻译下:
查询必询不是管理语句,或者开启了
。
查询的时间至少是的秒数,或者查询没有使用索引并且开启了。
查询至少检索了 的行数.
查询必要不会根据 的设置而被抑制。
二、在mysql5.5 中文参考手册可以找到log-queries-not-using-indexes的说明:
如果你结合--log-slow-queries使用该选项,未使用索引的查询也被记录到慢查询日志中。
通过上面的资料就可以知道,因为开启了log_queries_not_using_indexes造成后,未使用索引的查询是否被记录和slow_query_time的设置无关
解决办法一:
修改/etc/my.cnf
log_queries_not_using_indexes=0
然后重启服务器。
解决办法二:
在mysql 查询中执行
set global log_queries_not_using_indexes=0;
参考:
mysql5.5中文参考手册
本文出自 “” 博客,请务必保留此出处