首页 > 代码库 > 分析时间段内对表的操作次数
分析时间段内对表的操作次数
分析某个时间段内,表的select、insert、update、delete次数。需要用到percona-toolkit包中的一个工具pt-query-digest,脚本如下:
[root@syk ~]# cat get_list.sh #!/bin/bash set -x #slow_file=ai-db1-slow.log slow_file=$1 if [ $# != 1 ] ; then echo "USAGE: $0 slow.log" echo " e.g.: $0 api-db1-slow.log" exit 1; fi pt-query-digest --limit 10000 $slow_file > /tmp/tmp_file bn=`grep -n "# 1 0x" /tmp/tmp_file|awk -F ‘:‘ ‘{print $1}‘` tn=`grep -n "# Query 1:" /tmp/tmp_file |awk -F ‘:‘ ‘{print $1}‘` en=`expr $tn - 2` sed -n "$bn,$en"p /tmp/tmp_file > /tmp/table_file cat /tmp/table_file|awk ‘{print $6","$9","$10}‘ > /tmp/table_source /usr/local/mysql/bin/mysql -uroot -pxxxxxxxx -S /tmp/mysql_3308.sock <<EOF use sykdb; drop table slow_log; create table slow_log ( cnt varchar(30), type varchar(30), tname varchar(30) ); drop table slow_table; create table slow_table ( tname varchar(30), select_cnt varchar(30), insert_cnt varchar(30), update_cnt varchar(30), delete_cnt varchar(30) ); load data infile ‘/tmp/table_source‘ into table slow_log FIELDS TERMINATED BY ‘,‘; delete from slow_log where type=‘‘; insert into slow_table(tname) select distinct(tname) from slow_log; update slow_table t set t.select_cnt=(select sum(cnt) from slow_log l where l.type=‘select‘ and l.tname=t.tname group by l.tname); update slow_table t set t.insert_cnt=(select sum(cnt) from slow_log l where l.type=‘insert‘ and l.tname=t.tname group by l.tname); update slow_table t set t.update_cnt=(select sum(cnt) from slow_log l where l.type=‘update‘ and l.tname=t.tname group by l.tname); update slow_table t set t.delete_cnt=(select sum(cnt) from slow_log l where l.type=‘delete‘ and l.tname=t.tname group by l.tname); select * from slow_table; EOF #end of script
本文出自 “刚刚出壳的小鸟” 博客,请务必保留此出处http://qhd2004.blog.51cto.com/629417/1940512
分析时间段内对表的操作次数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。