MySQL之慢查询日志分析
Posted 峰哥ge
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL之慢查询日志分析相关的知识,希望对你有一定的参考价值。
在mysql命令行中查看慢查询日志是否打开了:
mysql> show variables like \'%slow_query%\'; +---------------------------+-------------------------------------------+ | Variable_name | Value | +---------------------------+-------------------------------------------+ | slow_query_log | OFF | | slow_query_log_file | /data/data_mysql/ip-172-31-22-29-slow.log | +---------------------------+-------------------------------------------+
从上面可以看出没有打开慢查询日志的功能,现在我们打开一下,修改配置文件即可,修改后重启服务器。慢查询还有一个值比较重要,就是知道慢查询的时间:
mysql> show variables like \'long_query_time\'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 6.000000 | +-----------------+----------+ 1 row in set (0.00 sec)
现在修改为两秒:
mysql> set long_query_time=2; Query OK, 0 rows affected (0.00 sec)
现在我们执行一个超过2秒的命令,看看效果:
mysql> select * from sbtest1 group by k order by c desc limit 1 ; +--------+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+ | id | k | c | pad | +--------+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+ | 453457 | 405843 | 99999937916-36259215105-74975791934-92968503070-23401591942-58585485414-51662851642-34478065889-45334022082-96106417569 | 77221010299-62957510796-01772448764-69834738016-84613386231 | +--------+--------+-------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------+ 1 row in set (2.18 sec)
现在我们查看一下慢查询日志;
以上是关于MySQL之慢查询日志分析的主要内容,如果未能解决你的问题,请参考以下文章
MySQL优化之慢日志分析(Anemometer+Pt-query-digest)