使用MySQLdumpslow统计慢日志b
00 分钟
2022-8-26

目的:

统计慢日志,优化SQL;

工具:

MySQLdumpslow,MySQLdumpslow是mysql自带的用来分析慢查询的工具;
Option Name
Description
Do not abstract all numbers to N and strings to 'S'
不要将所有数字都抽象为N,将字符串抽象为“ S”
Abstract numbers with at least the specified digits
后面跟数字,在名称中至少有n个数字抽象为数字
Write debugging information
Only consider statements that match the pattern
正则后边可以写一个正则匹配模式,大小写不敏感的
Display help message and exit
Host name of the server in the log file name
日志文件名中服务器的主机名
Name of the server instance
服务器实例的名称
Do not subtract lock time from total time
锁定时间
Reverse the sort order
返回记录
How to sort output
排序
Display only first num queries
返回多少条数据
Verbose mode
详细模式
默认情况下,mysqldumpslow按平均查询时间(等于-s at)排序。

案例:

平均访问次数最多的20条sql
平均查询时间最长倒序的前50条,并输出到日志中
查询结果如下: Count:查询次数; Time:执行时间; Lock:锁定时间; Rows:扫描行数; 这里未使用-a所以参数已经抽象,被N代替;

评论