分析某個(gè)時(shí)間段內(nèi),表的select、insert、update、delete次數(shù)。需要用到percona-toolkit包中的一個(gè)工具pt-query-digest,腳本如下:

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:
成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的
古交網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴![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
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文題目:分析時(shí)間段內(nèi)對(duì)表的操作次數(shù)-創(chuàng)新互聯(lián)
URL鏈接:http://jinyejixie.com/article40/cshceo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、域名注冊(cè)、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站收錄、網(wǎng)站制作、企業(yè)網(wǎng)站制作
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源:
創(chuàng)新互聯(lián)