如何用shell脚本取到日志文件 slow.log 中 # Query_time:大于 1 的内容,所提取到的内容从 # User@Host----到 sql 语句结束。
# Time: 150617 16:05:29
# User@Host : appserver[appserver] @ [172.31.0.76] Id: 2888
# Query_time: 3.315370 Lock_time: 0.000043 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528329;
update app_car_obd_status
SET speed = 80.0,
battery_voltage =11.899999618530273
where car_id = '00032332'
;
# User@Host : appserver[appserver] @ [172.31.0.76] Id: 2868
# Query_time: 1.525391 Lock_time: 0.000071 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528329;
update app_car_gps_status
SET car_id = '00057759',
din = 'M000000577500',
longitude = 106.57539,
latitude = 29.540447999999998
;
# Time: 150617 16:05:30
# User@Host : appserver[appserver] @ [172.31.0.76] Id: 2884
# Query_time: 2.049172 Lock_time: 0.000293 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528330;
update app_car_obd_status
SET car_id = '00071118',
din = 'M000000711090',
obd_time = '2015-06-17 14:24:07',
receive_time = '2015-06-17 14:23:59.505',
speed = 80.0
where car_id = '00071118'
;
# User@Host: appserver[appserver] @ [172.31.0.76] Id: 2887
# Query_time: 1.122752 Lock_time: 0.000212 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528330;
update app_car_obd_status
SET car_id = '00088473',
din = 'M000000884620',
obd_time = '2015-06-17 14:24:09',
receive_time = '2015-06-17 14:24:01.601',
speed = 80.0
# User@Host : appserver[appserver] @ [172.31.0.76] Id: 2888
# Query_time: 3.315370 Lock_time: 0.000043 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528329;
update app_car_obd_status
SET speed = 80.0,
battery_voltage =11.899999618530273
where car_id = '00032332'
;
# User@Host : appserver[appserver] @ [172.31.0.76] Id: 2868
# Query_time: 1.525391 Lock_time: 0.000071 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528329;
update app_car_gps_status
SET car_id = '00057759',
din = 'M000000577500',
longitude = 106.57539,
latitude = 29.540447999999998
;
# Time: 150617 16:05:30
# User@Host : appserver[appserver] @ [172.31.0.76] Id: 2884
# Query_time: 2.049172 Lock_time: 0.000293 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528330;
update app_car_obd_status
SET car_id = '00071118',
din = 'M000000711090',
obd_time = '2015-06-17 14:24:07',
receive_time = '2015-06-17 14:23:59.505',
speed = 80.0
where car_id = '00071118'
;
# User@Host: appserver[appserver] @ [172.31.0.76] Id: 2887
# Query_time: 1.122752 Lock_time: 0.000212 Rows_sent: 0 Rows_examined: 1
SET timestamp=1434528330;
update app_car_obd_status
SET car_id = '00088473',
din = 'M000000884620',
obd_time = '2015-06-17 14:24:09',
receive_time = '2015-06-17 14:24:01.601',
speed = 80.0
where car_id = '00088473'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果是想分析慢查询 可以使用工具分析 pt-query-digest
如果是show.log,把tmp.txt改为show.log即可,只是一个取出来的思路。
cat -n tmp.txt |grep 'Query_time' | awk -F'[: ]' '$5>1' | awk '{print $1}' >a.txt #把# Query_time: 后面大于1的所在的行数取出来.
cat a.txt |while read line;do qian=$(($line-1)); hou=$(($line+8)); sed -n "${qian},${hou}p" tmp.txt; done #把查到的那一行的前面1行和后面8行取出来
#FFFFFF;">#测试是能取出来,但可以后面有些是7行,取出来会有点混乱。