ITPub博客

首页 > 数据库 > MySQL > 【MySQL】慢查询日志不打印

【MySQL】慢查询日志不打印

原创 MySQL 作者:风尘_NULL 时间:2017-02-06 15:56:45 0 删除 编辑
测试环境修改 long_query_time=0.2
当执行性以下查询时,慢查询日志没有生效
mysql> select sleep(5);

+----------+
| sleep(5) |
+----------+
|        0 |
+----------+
1 row in set (5.00 sec)


⑴于是检查参数
mysql> show variables like '%query%';
+------------------------------+------------------+
| Variable_name                | Value            |
+------------------------------+------------------+
| binlog_rows_query_log_events | OFF              |
| ft_query_expansion_limit     | 20               |
| have_query_cache             | YES              |
| long_query_time              | 1.000000         |
| query_alloc_block_size       | 8192             |
| query_cache_limit            | 0                |
| query_cache_min_res_unit     | 4096             |
| query_cache_size             | 0                |
| query_cache_type             | OFF              |
| query_cache_wlock_invalidate | OFF              |
| query_prealloc_size          | 8192             |
| slow_query_log               | ON               |
| slow_query_log_file          | /mlogs/slow1.log |
+------------------------------+------------------+

发现配置正常

⑵于是检查以下两个参数
min_examined_row_limit、long-queries-not-using-indexes
mysql> show variables like 'min_examined_ro%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| min_examined_row_limit | 10    |
+------------------------+-------+
1 row in set (0.00 sec)
mysql> show variables like 'log_queries_not_using_indexes';
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF   |
+-------------------------------+-------+


然后将min_examined_row_limit置为0,慢查询会记录


两个参数:
 log_queries_not_using_indexes,为on时表示记录没用到索引的查询,即使没有超过long_query_time
 min_examined_row_limit,表示查询超过多少条就记录(当 min_examined_row_limit=on的时候)


原因:select sleep(5)语句查询没有记录(即<min_examined_row_limit的值),且没用到索引

</min_examined_row_limit的值),且没用到索引

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30221425/viewspace-2133122/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
腾讯科技(深圳)有限公司 DBA

注册时间:2015-04-24

  • 博文量
    76
  • 访问量
    238219