MySQL數據庫學習之SQL語句如何優化?數據庫開發
阿新 • • 發佈:2018-06-21
郵箱 list key 推薦 sin ges 操作 開關 RoCE 1) 現場抓出慢查詢語句 show full processlist;
2) 配置參數:
slow_query_log_file = ON 慢查詢開啟開關
long_query_time =2 記錄大於2秒的sql語句
log_queries_not_using_indexes = ON 沒有使用索引的sql語句
slow_query_log_file = /application/mysql-5.6.34/data/db01-slow.log 慢log文件
min_examined_row_limit = 800 記錄結果集大於800行的sql語句
3) 按天輪詢:slow_log.log
4) 慢查詢日誌分析工具--mysqlsla或pt-query-digest(推薦)
5) 每天晚上0點定時分析慢查詢 發到核心開發 DBA分析 及高級運維 cto的郵箱
DBA分析給出優化建議--核心開發確認更改--DBA線上操作處理
6 )定期使用pt-duplicate-key-checker檢查並刪除++
定期使用pt-index-usage 工具檢查並刪除
7 )使用explain及set profile優化sql語句
MySQL數據庫學習之SQL語句如何優化?數據庫開發