MySQL的SQL语句如何优化?老男孩MySQL培训

    /    2019-05-30

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


(0)

分享至