ITPub博客

首页 > 数据库 > MySQL > 用命令过滤MySQL慢查询日志

用命令过滤MySQL慢查询日志

原创 MySQL 作者:壹頁書 时间:2015-11-17 17:36:25 0 删除 编辑
有一台web服务器异常.
CPU耗尽导致所有请求阻塞,偶发,一般持续时间5-10分钟.

在该时间段,数据库整体负载正常.

使用命令查询慢日志.
指定某个IP,找到查询时间大于100s,并且显示当时执行的SQL

cat slow-log | sed  '/\#/{N;N;s/\n//g}'  | grep "Query_time: [1-9][0-9]\{2\}\." -n20

或者

cat slow-log | sed  '/\#/{N;N;s/\n//g}'  | grep "127\.0\.0\.1.*Query_time: [1-9][0-9]\{2\}\." -A5

-bash-4.1$ cat slow-log | sed  '/\#/{N;N;s/\n//g}'  | grep "Query_time: [1-9][0-9]\{2\}\."  
# Time: 151117 15:49:01# User@Host: xx[xx] @  [IP]  Id: 12827130# Query_time: 103.301519  Lock_time: 0.000080 Rows_sent: 716360  Rows_examined: 1782770
# Time: 151117 15:57:41# User@Host: xx[xx] @  [IP]  Id: 12827130# Query_time: 102.565315  Lock_time: 0.000088 Rows_sent: 1066410  Rows_examined: 1066410
# Time: 151117 16:33:51# User@Host: xx[xx] @  [IP]  Id: 12827970# Query_time: 265.482413  Lock_time: 0.000253 Rows_sent: 423799  Rows_examined: 5864759
# Time: 151117 16:34:02# User@Host: xx[xx] @  [IP]  Id: 12827913# Query_time: 314.793697  Lock_time: 0.000266 Rows_sent: 897670  Rows_examined: 6338629

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29254281/viewspace-1839933/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 正则表达式学习
请登录后发表评论 登录
全部评论

注册时间:2013-10-19

  • 博文量
    620
  • 访问量
    6339985