您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
分析某个时间段内,表的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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。