mysql自带的慢查询日志分析工具mysqldumpslow如何使用

--------------如何使用mysqldumpslow工具对日志进行分析--------------

使用命令查找mysqldumpslow工具路径

find / -name mysqldumpslow

我的查询返回路径为

/usr/local/mysql/bin/mysqldumpslow

访问次数最多的10条sql语句

/usr/local/mysql/bin/mysqldumpslow -s c -t 10 /home/wwwlogs/mysql_slow_querys.log

返回记录最多的20条sql语句

/usr/local/mysql/bin/mysqldumpslow -s r -t 10 /home/wwwlogs/mysql_slow_querys.log

按照时间返回前10条里面含有left join的sql语句

/usr/local/mysql/bin/mysqldumpslow -t 10 -s t -g “left join” /home/wwwlogs/mysql_slow_querys.log

使用命令查看mysqldumpslow参数说明

/usr/local/mysql/bin/mysqldumpslow -help

mysqldumpslow常用参数

-s,是order的顺序,说明写的不够详细,主要有
c,t,l,r和ac,at,al,ar,分别是按照query次数,时间,lock的时间和返回的记录数来排序,前面加了a的时倒序
-t,是top n的意思,即为返回前面多少条的数据
-g,后边可以写一个正则匹配模式,大小写不敏感的

mysqldumpslow完整参数说明如下:
--verbose verbose
--debug debug
--help write this text to standard output

-v verbose
-d debug
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default
al: average lock time
ar: average rows sent
at: average query time
c: count
l: lock time
r: rows sent
t: query time
-r reverse the sort order (largest last instead of first)
-t NUM just show the top n queries
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup script)
-l don't subtract lock time from total time