MySQL5.6 慢日誌開啓
開啓慢日誌:set global long_query_time=1;
檢查慢日誌是否開啓:show variables like '%slow_query_log%';
。
mysql> show variables like '%slow_query_log%';
+---------------------+--------------------------------------+
| Variable_name | Value |
+---------------------+--------------------------------------+
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/ae63ff954753-slow.log |
+---------------------+--------------------------------------+
2 rows in set (0.00 sec)
slow_query_log
: 是否開啓慢日誌slow_query_log_file
: 慢日誌文件
設置慢日誌時長爲 0.9 秒:SET GLOBAL long_query_time=0.9;
,注意 SET GLOBAL
才能全局生效,否則則是當前會話纔有效。
查看慢日誌時長:show GLOBAL variables like "long_query_time";
mysql> SHOW GLOBAL VARIABLES LIKE "long_query_time";
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 0.900000 |
+-----------------+----------+
1 row in set (0.00 sec)
如何查看 MySQL 的慢日誌?TODO
Why I could not alter the variable long_query_time variable at runtime