開啓mysql慢查詢和死鎖日誌

顯示慢查詢狀態及日誌目錄

show variables like '%slow_query_log%';
複製代碼
+---------------------+--------------------------------------+
| Variable_name       | Value                                |
+---------------------+--------------------------------------+
| slow_query_log      | OFF                                  |
| slow_query_log_file | /var/lib/mysql/9e6bec7d7160-slow.log |
+---------------------+--------------------------------------+
複製代碼
開啓慢查詢

說明: 1開啓;0關閉;mysql

set global slow_query_log = 1;
複製代碼

顯示慢查詢閾值(單位秒)

默認執行時間超過10s纔會被記錄到日誌sql

show variables like '%long_query%';
複製代碼
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
複製代碼
設置慢查詢閾值

注意:設置後須要從新打開mysql客戶端才能到最新的值spa

set global long_query_time = 0.8;
複製代碼

查看死鎖的日誌是否開啓

show variables like "%innodb_print_all_deadlocks%";
複製代碼
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| innodb_print_all_deadlocks | OFF   |
+----------------------------+-------+
複製代碼
開啓記錄死鎖
set global innodb_print_all_deadlocks=1
複製代碼
相關文章
相關標籤/搜索