在使用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: 1839SET 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.sh2007-12-28 00:02:28 +0000+++ b/scripts/mysqldumpslow.sh2008-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//;