mysqldumpslow bug— does not aggregate times

在使用mysqldumpslow 对慢查询日志进行分析时,发现有关于查询时间,锁住时间,检查的行数等不能正确显示,都是N

How to repeat:
I activated the slow query log and produced some slow queries. The slow query log contains now entries like 

# Time: 080129 11:51:12
# User@Host: root[root] @ localhost []
# Query_time: 0.001565  Lock_time: 0.000051 Rows_sent: 1  Rows_examined: 1839
SET timestamp=1201603872;
SELECT COUNT(*) FROM city_huge, Country WHERE city_huge.CountryCode=Country.Code AND Country.Continent='Asia' AND Country.Population < 1000000;

If I now run mysqldumpslow the aggregated times are always 0.00:

Count: 8  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  # Query_time: N.N  Lock_time: N.N Rows_sent: N  Rows_examined: N
  SET timestamp=N;
  SELECT COUNT(*) FROM city_huge, Country WHERE city_huge.CountryCode=Country.Code AND Country.Continent='S' AND Country.Population < N

这是一个bug见于 mysqldumpslow bug以及 mysqldumpslow bug

      Change the capturing regex to account for decimal also.
modified:
  scripts/mysqldumpslow.sh

=== modified file 'scripts/mysqldumpslow.sh'
--- a/scripts/mysqldumpslow.sh	2007-12-28 00:02:28 +0000
+++ b/scripts/mysqldumpslow.sh	2008-07-07 22:56:53 +0000
@@ -83,7 +83,7 @@ while ( defined($_ = shift @pending) or 
     s/^#? Time: \d{6}\s+\d+:\d+:\d+.*\n//;
     my ($user,$host) = s/^#? User\@Host:\s+(\S+)\s+\@\s+(\S+).*\n// ? ($1,$2) : ('','');
 
-    s/^# Query_time: (\d+)  Lock_time: (\d+)  Rows_sent: (\d+).*\n//;
+    s/^# Query_time: ([0-9.]+)  Lock_time: ([0-9.]+)  Rows_sent: ([0-9.]+).*\n//;
     my ($t, $l, $r) = ($1, $2, $3);
     $t -= $l unless $opt{l};

修复:

[root@mfsmaster ~]# locate mysqldumpslow
/usr/bin/mysqldumpslow
/usr/local/mysql-search/bin/mysqldumpslow
之后直接修改文件:

vi /usr/bin/mysqldumpslow

s/^# Query_time: (\d+)  Lock_time: (\d+)  Rows_sent: (\d+).*\n//;

修改为:

s/^# Query_time: ([0-9.]+)  Lock_time: ([0-9.]+)  Rows_sent: ([0-9.]+).*\n//;

或者:
s/^# Query_time: (\d+\.?\d*)\s+Lock_time: (\d+\.?\d*)\s+Rows_sent: (\d+\.?\d*).*\n//;





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值