MySQL开启慢查询
admin 发布于:2013-11-1 16:21 分类:Linux 有 1665 人浏览,获得评论 0 条 标签: mysql 慢查询
查看/设置“慢查询”的时间定义
mysql> show variables like "long%";
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 1 |
+-----------------+----------+
1 row in set (0.00 sec)
如上述语句输出,“慢查询”的时间定义为1秒(方便测试,一般设置为1-10秒)。使用下面语句定义“慢查询”时间
mysql> set long_query_time=1;
Query OK, 0 rows affected (0.00 sec)
开启“慢查询”记录功能
mysql> show variables like "slow%";
+---------------------+------------------------------------+
| Variable_name | Value |
+---------------------+------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /opt/mysql/data/localhost-slow.log |
+---------------------+------------------------------------+
3 rows in set (0.00 sec)
上述语句查看“慢查询”的配置信息,你可以自定义日志文件的存放,但必须将 slow_query_log 全局变量设置为“ON”状态,执行以下语句:
mysql> set global slow_query_log=ON;
Query OK, 0 rows affected (0.01 sec)
结果:
mysql> show variables like "slow%";
+---------------------+------------------------------------+
| Variable_name | Value |
+---------------------+------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /opt/mysql/data/localhost-slow.log |
+---------------------+------------------------------------+
3 rows in set (0.00 sec)