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之慢查询日志分析

上一篇:JVM 优化问题


下一篇:吴裕雄 oracle 管理数据表对象