您的位置:首页 > 博客中心 > 数据库 >

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”中说慢查询记录的条件:

  1. The query must either not be an administrative statement, or                    must be enabled.

  2. The query must have taken at least           seconds, or                    must be enabled and the query used no indexes for row lookups.

  3. The query must have examined at least           rows.

  4. The query must not be suppressed according to the                    setting.

粗略地翻译下:

  1. 查询必询不是管理语句,或者开启了

  2. 查询的时间至少是的秒数,或者查询没有使用索引并且开启了。

  3. 查询至少检索了 的行数.

  4. 查询必要不会根据  的设置而被抑制。


二、在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中文参考手册





本文出自 “” 博客,请务必保留此出处

热门排行

今日推荐

热门手游