MySQL性能优化 - 慢查询日志
2022-09-26 本文已影响0人
右耳菌
1. 慢查询日志概述
- 说明
该日志记录执行时间超过阈值的SQL语句
注意:慢查询日志并不仅仅只记录select,update这种数据修改的SQL语句执行过长也会被记录
- 参数配置
慢SQL日志是Mysq(服务器提供的功能。在提供关键性监控数据的同时,还能够保持比较低的性能开销。
建议开启!
2. 日志内容分析
日志分析辅助工具:mysqldumpslow、pt-query-digest
-
mysqldumpslow
指令使用帮助文档
[root@192 src]# mysqldumpslow --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL slow query log. Options are
--verbose verbose
--debug debug
--help write this text to standard output
-v verbose
-d debug
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default
al: average lock time
ar: average rows sent
at: average query time
c: count
l: lock time
r: rows sent
t: query time
-r reverse the sort order (largest last instead of first)
-t NUM just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup script)
-l don't subtract lock time from total time
3. 生产环境中如何发现慢SQL
如加入ELK 等
如果觉得有收获,欢迎点赞和评论,更多知识,请点击关注查看我的主页信息哦~