標籤:tab 分析 exe set miss 應該 使用 sel 故障
通過指令碼,重新整理觀察mysql的status,觀察是否有周期性故障活波動,
一般由訪問高峰或者緩衝失效引起,家緩衝並更改緩衝失效策略,是失效時間分散或頁面定時失,
SHOW PROCESSLIST顯示哪些線程正在運行。
您也可以使用mysqladmin processlist語句得到此資訊。如果您有SUPER許可權,您可以看到所有線程。否則,您只能看到您自己的線程
mysql 開啟慢查詢日誌
slow_query_log 這個參數設定為ON,可以捕獲執行時間超過一定數值的SQL語句。long_query_time 當SQL語句執行時間超過此數值時,就會被記錄到日誌中,建議設定為1或者更短slow_query_log_file 記錄日誌的檔案名稱。log_queries_not_using_indexes 這個參數設定為ON,可以捕獲到所有未使用索引的SQL語句,儘管這個SQL語句有可能執行得挺快。
使用profiler來分析一條query的執行時間和效能瓶頸,
開啟 profiling ;
set profiling=1;
隨便執行一條語句 select count(*) from user where id>2;
show profiles;
得到
+----------+------------+--------------------------------------+| Query_ID | Duration | Query |+----------+------------+--------------------------------------+| 2 | 0.00009200 | set profiling=1 || 5 | 0.02003525 | select count(*) from user where id>2 |+----------+------------+--------------------------------------+
包含一個query_id和執行時間和query語句
通過query_id可以查看到更詳細的資訊;
show profile cpu ,block io for query 5;
+----------------------+----------+----------+------------+--------------+---------------+| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |+----------------------+----------+----------+------------+--------------+---------------+| starting | 0.000170 | 0.000000 | 0.000000 | 0 | 0 || checking permissions | 0.000019 | 0.000000 | 0.000000 | 0 | 0 || Opening tables | 0.000033 | 0.000000 | 0.000000 | 0 | 0 || init | 0.000061 | 0.000000 | 0.000000 | 0 | 0 || System lock | 0.000021 | 0.000000 | 0.000000 | 0 | 0 || optimizing | 0.000021 | 0.000000 | 0.000000 | 0 | 0 || statistics | 0.010826 | 0.000000 | 0.000000 | 184 | 0 || preparing | 0.000041 | 0.000000 | 0.000000 | 0 | 0 || executing | 0.000005 | 0.000000 | 0.000000 | 0 | 0 || Sending data | 0.008731 | 0.008000 | 0.000000 | 0 | 0 || end | 0.000020 | 0.000000 | 0.000000 | 0 | 0 || query end | 0.000018 | 0.000000 | 0.000000 | 0 | 0 || closing tables | 0.000012 | 0.000000 | 0.000000 | 0 | 0 || freeing items | 0.000032 | 0.000000 | 0.000000 | 0 | 0 || cleaning up | 0.000027 | 0.000000 | 0.000000 | 0 | 0 |+----------------------+----------+----------+------------+--------------+---------------+
對mysql伺服器的最佳化不要一上來就去最佳化sql語句,應該首先觀察全域情況,至少要先搞清楚
問題出在哪,應該使用指令碼來觀察伺服器一段時間(一天或更長)的健康情況,比如cpu,io,進程串連數等
最後才分析具體原因處在哪裡;針對解決
mysql最佳化思路