mysqldumpslow 慢日志信息提取工具

mysqldumpslow解析慢日志,并按照指定的规则对慢SQL进行汇总,先看看有什么参数:

[root@slave bin]# mysqldumpslow --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]

Parse and summarize the MySQL slow query log. Options are

  --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

语法:
mysqldumpslow [options] [log_file ...]

参数解析

--verbose,-v  输出详细信息
--debug,-d    输出debug信息
-s            指定输出的排序规则,有如下几种:
• t, at: 按照查询时间/平均查询时间排序
• l, al: 按照锁等待时间/平均锁等待时间排序
• r, ar: 按照返回行数/平均返回行数排序
• c: 按照慢SQL出现次数排序
-r            输出结果反序排序,默认是desc的顺序
-t NUM        指定显示多少条慢SQL
-a            不将数字抽象成N、字符抽象成S
-n NUM        将超过N个数字的数值字符抽象显示
-g PATTERN    正则匹配慢SQL
-l            total time包含lock time   

输出样例:

--按照平均执行时间排序,查出排名前10条SQL
[root@master data]# mysqldumpslow -s at -t 10 master-slow.log 

Reading mysql slow query log from master-slow.log
Count: 1  Time=0.35s (0s)  Lock=0.02s (0s)  Rows=1.0 (1), root[root]@localhost
  select count(*) from test

Count: 1  Time=0.06s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  drop table test1

Count: 1  Time=0.04s (0s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  desc select distinct id from tab order by col1 limit N,N

Count: 1  Time=0.02s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  create table test1(id int not null primary key,col1 int,col2 int)

Count: 1  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  delete from test1 where id=N

Count: 4  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=2.0 (8), root[root]@localhost
  show variables like 'S'

Count: 1  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  replace into test1 values (N,N,N)

Count: 1  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  update tab set col1=N where id=N

Count: 2  Time=0.01s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  insert into test1 values (null,N,N),(null,N,N),(null,N,N)

Count: 2  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  insert into test1 values (null,N,N) on duplicate key update col2=col2+N

你可能感兴趣的:(MySQL)