使用MySQLdumpslow统计慢日志

目的:

统计慢日志,优化SQL;

工具:

MySQLdumpslow,MySQLdumpslow是mysql自带的用来分析慢查询的工具;

Option NameDescription
-aDo not abstract all numbers to N and strings to 'S'不要将所有数字都抽象为N,将字符串抽象为“ S”
-nAbstract numbers with at least the specified digits后面跟数字,在名称中至少有n个数字抽象为数字
--debugWrite debugging information
-gOnly consider statements that match the pattern正则后边可以写一个正则匹配模式,大小写不敏感的
--helpDisplay help message and exit
-hHost name of the server in the log file name日志文件名中服务器的主机名
-iName of the server instance服务器实例的名称
-lDo not subtract lock time from total time锁定时间
-rReverse the sort order返回记录
-sHow to sort output排序
-tDisplay only first num queries返回多少条数据
--verboseVerbose mode详细模式

默认情况下,mysqldumpslow按平均查询时间(等于-s at)排序。

-s 后面可以跟参数来选择排序方式
    c:访问计数
    l:锁定时间
    r:返回记录
    al:平均锁定时间
    ar:平均访问记录数
    at:平均查询时间

案例:

平均访问次数最多的20条sql

mysqldumpslow -s ar -t 20 sqldlow.log

平均查询时间最长倒序的前50条,并输出到日志中

mysqldumpslow -s at -t 50 /var/lib/mysql/slow.log > /tmp/slowsql.log

查询结果如下: Count:查询次数; Time:执行时间; Lock:锁定时间; Rows:扫描行数; 这里未使用-a所以参数已经抽象,被N代替;

Count: 2  Time=3.00s (6s)  Lock=0.00s (0s)  Rows=4103.0 (8206), root[root]@2hosts
  SELECT * FROM `user` LIMIT N OFFSET N
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值