您好,登錄后才能下訂單哦!
分析某個時間段內,表的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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。