手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL 慢查询日志(Slow Query Log)

[日期:2014-10-07] 来源:Linux社区  作者:leshami [字体:大 中 小]

4、格式化慢查询日志

结构化慢查询日志就是把慢查询日志中的重要信息按照便于阅读以及按照特定的排序方式来提取SQL。
这种方式有点类似于Oracle中有个tkprof来格式化oracle的trace文件。
对于前面的慢查询日志我们使用MySQLdumpslow来提取如下:

SUSE11b:~ # mysqldumpslow -s at,al /var/lib/mysql/suse11b-slow.log
Reading mysql slow query log from /var/lib/mysql/suse11b-slow.log
Count: 4  Time=16.87s (67s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  insert into tb_slow select * from tb_slow

Count: 1  Time=0.20s (0s)  Lock=0.00s (0s)  Rows=1.0 (1), root[root]@localhost
  select count(*) from tb_slow

Count: 1  Time=1.57s (1s)  Lock=0.00s (0s)  Rows=83.0 (83), root[root]@localhost
  select table_schema,table_name,count(*) from tb_slow
  group by table_schema,table_name order by N,N

#以下是按照最大耗用时间排最后,只显示2条的方式格式化日志文件
suse11b:~ # mysqldumpslow -r -t 2 /var/lib/mysql/suse11b-slow.log
Reading mysql slow query log from /var/lib/mysql/suse11b-slow.log
Count: 1  Time=1.57s (1s)  Lock=0.00s (0s)  Rows=83.0 (83), root[root]@localhost
  select table_schema,table_name,count(*) from tb_slow
  group by table_schema,table_name order by N,N

Count: 4  Time=16.87s (67s)  Lock=0.00s (0s)  Rows=0.0 (0), root[root]@localhost
  insert into tb_slow select * from tb_slow
 
#获取mysqldumpslow的帮助信息
suse11b:~ # 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        #query的次数
                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

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/107694.htm

linux
相关资讯       MySQL日志  MySQL慢查询日志  MySQL慢查询 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款