使用 show status 命令
-
查看查詢時間超過long_query_time秒的查詢的個數。
show status like 'slow_queries';
-
查看創建時間超過slow_launch_time秒的線程數。
show status like 'slow_launch_threads';
-
查看不能立即獲得的表的鎖的次數。如果該值較高,並且有性能問題,你應首先優化查詢,然後拆分表或使用複製。
show status like 'table_locks_waited';
-
查看立即獲得的表的鎖的次數。
show status like 'table_locks_immediate';
-
查看激活的(非睡眠狀態)線程數。
show status like 'threads_running';
-
查看創建用來處理連接的線程數。如果Threads_created較大,你可能要增加thread_cache_size值。
show status like 'threads_created';
-
查看當前打開的連接的數量。
show status like 'threads_connected';
-
查看線程緩存內的線程的數量。
show status like 'threads_cached';
-
查看試圖連接到MySQL(不管是否連接成功)的連接數
show status like 'connections';
-
查看delete語句的執行數
show [global] status like 'com_delete';
-
查看update語句的執行數
show [global] status like 'com_update';
-
查看insert語句的執行數
show [global] status like 'com_insert';
-
查看select語句的執行數
show [global] status like 'com_select';
-
查看MySQL本次啓動後的運行時間(單位:秒)
show status like 'uptime';
如何修改慢查詢
MySQL默認10秒內沒有響應SQL結果,則爲慢查詢可以去修改MySQL慢查詢默認時間
-
查詢慢查詢時間
show variables like 'long_query_time';
-
修改慢查詢時間
set long_query_time=1; ---但是重啓mysql之後,long_query_time依然是my.ini中的值