不能盲目的作優化,要先找準問題所在,是cpu,內存,io?仍是峯值,語句?mysql
mysql> show status; 或 mysqladmin exts;sql
mysql> show processlist;服務器
狀態說明:mysql優化
converting HRAP to MyIsAM 把查詢結果放在磁盤(取得數據太多)工具
create tmp table 建立臨時表(索引須要優化)性能
copying to tmp table to disk 把內存臨時表複製到磁盤(索引須要優化,索引字段)測試
locked 被其餘查詢鎖住(事務)優化
logging slow query 記錄慢查詢spa
準備:日誌
檢查是否開啓profiling
show variables like 'profiling';
開啓profiling
set profiling=on;
show profiles; //顯示執行語句的執行信息(含語句query_id) show profile for query 1; //獲取 query_id 爲1的語句的執行信息 explain (sql語句) \G; //解析sql執行計劃
mysql> show variables like 'show_query%'; //能夠看到是否開啓,和日誌路徑 mysql> show variables like '%long_query%'; //慢查詢臨界值,超過該值則記入慢查詢 //開啓 mysql> set global slow_query_log=1;
mysqladmin -uroot ext|awk 'Queries/{q=$4}/Threads_connected/{c=$4}/Threads_running/{r=$4}END{printf("%d %d %d\n",q,c,r)}'
待續……