mysql命令列開啟慢查詢日誌的方法:執行【set global slow_query_log='ON';】語句即可開啟。執行【show variables like "%slow%";】語句可以檢查慢查詢日誌是否已開啟。
具體方法:
(推薦教學:mysql教學)
檢視預設慢查詢的時間10秒
mysql> show variables like "%long%"; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 1 row in set (0.00 sec)
設定成3秒,加上global,退出再次進入生效
mysql> set global long_query_time=3; Query OK, 0 rows affected (0.00 sec)
查看一下慢查詢是不是已經開啟
mysql> show variables like "%slow%"; +---------------------+---------------------------------+ | Variable_name | Value | +---------------------+---------------------------------+ | log_slow_queries | OFF | | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | /usr/local/mysql/mysql-slow.log | +---------------------+---------------------------------+ 4 rows in set (0.00 sec)
啟用慢查詢
mysql> set global slow_query_log='ON'; Query OK, 0 rows affected (0.28 sec)
查看是否已開啟
mysql> show variables like "%slow%"; +---------------------+---------------------------------+ | Variable_name | Value | +---------------------+---------------------------------+ | log_slow_queries | ON | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /usr/local/mysql/mysql-slow.log | +---------------------+---------------------------------+ 4 rows in set (0.00 sec)
相關推薦:php訓練
以上是mysql命令列怎麼開啟慢查詢日誌的詳細內容。更多資訊請關注PHP中文網其他相關文章!