在使用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//;