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语句