mysql系列~慢日誌

零 參數
  log_queries_not_using_indexes 建議關閉
  long_query_time 慢日誌記錄時間
  min_examined_row_limit參數表示SQL執行過程中掃描的行數閾值,如果掃描的行數小於該參數設置的值,即使SQL執行耗時大於慢查詢閾值,也不會記錄到慢查詢日誌中,該參數默認值爲0。

一 mysqldumpslow
 相關命令
1 按照執行次數排序
   mysqldumpslow -s c(執行次數) -t(top) num slow.log
2 按照執行時間排序(總時間,非單次執行時間)
   mysqldumpslow -s t(執行時間) -t(top) num slow.log
3 按照掃描行數最多(執行總行數)
   mysqldumpslow -s r(掃描行數) -t(top) num slow.log
二   pt-query-digst
 相關命令 
  pt-query-digest slow.log --since 'start_time' --until 'end_time'> > slow_report.log

三 避免慢查詢

 1 mysql設置參數 max_execution_times 

   1 單位是毫秒,可以和研發確定一個閾值,防止長時間查詢

   2 超時報錯: ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded

   3 對於特殊對象(存儲過程事件等無法限制)

 2 利用pt-kill工具

  pt-kill --defaults-file=/etc/my.cnf --password 123456 --busy-time 60 --match-info "SELECT|select"  --print --kill  --victims all --interval 30 -kill超過60s的select語句

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章