免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4502 | 回复: 7
打印 上一主题 下一主题

[文本处理] 如何按照时间段打印mysql的慢日志 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-09-25 11:25 |只看该作者 |倒序浏览
本帖最后由 viato 于 2013-09-25 11:56 编辑

请教大家,如何按照时间段打印mysql的慢日志,比如打印下面15:13分到18点前的日志
  1. # Time: 130924 14:30:13
  2. # User@Host: test[test] @ localhost []
  3. # Query_time: 19.286527  Lock_time: 0.000025 Rows_sent: 0  Rows_examined: 1
  4. SET timestamp=1380007813;
  5. DELETE FROM functions WHERE  (triggerid IN (15632));
  6. # Time: 130924 15:13:08
  7. # User@Host: test[test] @ localhost []
  8. # Query_time: 19.069534  Lock_time: 0.000064 Rows_sent: 0  Rows_examined: 1
  9. SET timestamp=1380007813;
  10. update items set lastclock=1380007790,prevorgvalue='105201685955.000000',prevvalue=lastvalue,lastvalue='16795.633333' where itemid=18440;
  11. # Time: 130924 17:16:34
  12. # User@Host: test[test] @ localhost []
  13. # Query_time: 3.956485  Lock_time: 0.000031 Rows_sent: 0  Rows_examined: 500
  14. SET timestamp=1380014014;
  15. delete from trends where itemid=31165 limit 500;
  16. # User@Host: test[test] @ localhost []
  17. # Query_time: 9.649595  Lock_time: 0.000051 Rows_sent: 0  Rows_examined: 1
  18. SET timestamp=1380007813;
  19. UPDATE sessions SET lastaccess=1380007803 WHERE sessionid='11a6a446e80b9b559c555959f4ca5487';
  20. # User@Host: test[test] @ localhost []
  21. # Query_time: 9.193245  Lock_time: 0.000049 Rows_sent: 0  Rows_examined: 0
  22. use test;
  23. SET timestamp=1380007813;
  24. REPLACE INTO settings (name,value) VALUES ('poller_lastrun',1380007803);
  25. # Time: 130924 16:13:08
  26. # User@Host: test[test] @ localhost []
  27. # Query_time: 7.538226  Lock_time: 0.000025 Rows_sent: 0  Rows_examined: 500
  28. use test;
  29. SET timestamp=1380010388;
  30. delete from trends where itemid=24804 limit 500;
  31. # Time: 130924 17:13:34
  32. # User@Host: test[test] @ localhost []
  33. # Query_time: 3.956485  Lock_time: 0.000031 Rows_sent: 0  Rows_examined: 500
  34. SET timestamp=1380014014;
  35. delete from trends where itemid=31165 limit 500;
  36. # Time: 130924 18:13:51
  37. # User@Host: test[test] @ localhost []
  38. # Query_time: 3.552062  Lock_time: 0.000019 Rows_sent: 0  Rows_examined: 120
  39. SET timestamp=1380017631;
  40. delete from history_uint where itemid=26171 and clock<1379412820;
  41. # Time: 130924 19:14:15
  42. # User@Host: test[test] @ localhost []
  43. # Query_time: 3.631823  Lock_time: 0.000029 Rows_sent: 0  Rows_examined: 77
  44. SET timestamp=1380021255;
复制代码

论坛徽章:
1
2015亚冠之吉达阿赫利
日期:2015-09-09 16:42:38
2 [报告]
发表于 2013-09-25 11:41 |只看该作者
按时间排序

论坛徽章:
0
3 [报告]
发表于 2013-09-25 11:43 |只看该作者
就是不知道用 awk怎么去排里面的时间,

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [报告]
发表于 2013-09-25 12:22 |只看该作者
回复 1# viato

How about this

$ awk -vs="15:13:00" -ve="18:00:00" '/^# Time:/{if(s<$NF&&$NF<e)P=1;else P=0}P' FILE

论坛徽章:
0
5 [报告]
发表于 2013-09-25 13:05 |只看该作者
回复 4# jason680


    膜拜呀,可以请教一下,里面的P是什么意思吗,这个P没有看懂

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
6 [报告]
发表于 2013-09-25 13:42 |只看该作者
回复 5# viato


    一个普通的自定义变量。通过它的值是零还是非零来决定是否输出。

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
7 [报告]
发表于 2013-09-25 13:48 |只看该作者
本帖最后由 jason680 于 2013-09-25 13:52 编辑

回复 5# viato

there is simple rule "CONDITION{ACTIONS}" for awk

default ACTIONS is "print $0"
default CONDITION is "TRUE"

the last one P will be the same function: P{print $0}


--------------------
and there is simple way to set P value
$ awk -vs="15:13:00" -ve="18:00:00" '/^# Time:/{P=(s<$NF&&$NF<e)?1:0}P' FILE

论坛徽章:
0
8 [报告]
发表于 2013-09-25 14:10 |只看该作者
谢谢大家,我自己去消化一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP