pt-archiver數(shù)據(jù)刪除、遷移工具使用-創(chuàng)新互聯(lián)

1. 數(shù)據(jù)庫(kù)連接參數(shù)

參數(shù) 說明
A字符編碼
D庫(kù)
F從文件讀取選項(xiàng)
L加載數(shù)據(jù)本地文件
P端口
Ssocket文件
a執(zhí)行查詢的數(shù)據(jù)庫(kù)
b如果是true, 禁用SQL_LOG_BIN
h數(shù)據(jù)庫(kù)地址
i查詢使用的索引
m插件模塊名稱
p數(shù)據(jù)庫(kù)密碼
t
u用戶名

2. 常用參數(shù)

參數(shù) 默認(rèn)值 說明
--limit 10000每次取1000行數(shù)據(jù)用pt-archive處理,Number of rows to fetch and archive per statement.
--txn-size 1000設(shè)置1000行為一個(gè)事務(wù)提交一次,Number of rows pertransaction.
--where 'id<3000'設(shè)置操作條件
--progress 5000每處理5000行輸出一次處理信息
--statistics輸出執(zhí)行過程及最后的操作統(tǒng)計(jì)
--charset=UTF8指定字符集為UTF8
--bulk-delete批量刪除source上的舊數(shù)據(jù)(例如每次1000行的批量刪除操作)
--bulk-insert批量插入數(shù)據(jù)到dest主機(jī) (看dest的general log發(fā)現(xiàn)它是通過在dest主機(jī)上LOAD DATA LOCAL INFILE插入數(shù)據(jù)的)
--replace將insert into 語句改成replace寫入到dest庫(kù)
--sleep 120每次歸檔了limit個(gè)行記錄后的休眠120秒(單位為秒)
--file '/root/test.txt'導(dǎo)出的文件路徑
--purge刪除source數(shù)據(jù)庫(kù)的相關(guān)匹配記錄
--header輸入列名稱到首行(和--file一起使用)
-no-check-charset不指定字符集
--check-columns檢驗(yàn)dest和source的表結(jié)構(gòu)是否一致,不一致自動(dòng)拒絕執(zhí)行(不加這個(gè)參數(shù)也行。默認(rèn)就是執(zhí)行檢查的)
--no-check-columns不檢驗(yàn)dest和source的表結(jié)構(gòu)是否一致,不一致也執(zhí)行(會(huì)導(dǎo)致dest上的無法與source匹配的列值被置為null或者0)
--chekc-interval默認(rèn)1s檢查一次
--local不把optimize或analyze操作寫入到binlog里面(防止造成主從延遲巨大)
--retries超時(shí)或者出現(xiàn)死鎖的話,pt-archiver進(jìn)行重試的間隔(默認(rèn)1s)
--no-version-check目前為止,發(fā)現(xiàn)部分pt工具對(duì)阿里云RDS操作必須加這個(gè)參數(shù)
--analyze=ds操作結(jié)束后,優(yōu)化表空間(d表示dest,s表示source)

2. example

1. 刪除老數(shù)據(jù)

pt-archiver \
--source h=localhost,u=root,p=1234,P=3306,D=test,t=t \
--no-check-charset --where ‘a(chǎn)<=376‘ --limit 10000 --txn-size 1000 --purge

2. 復(fù)制數(shù)據(jù)到其他mysql實(shí)例,且不刪除source的數(shù)據(jù)(指定字符集):

/usr/bin/pt-archiver \
--source h=localhost,u=root,p=1234,P=3306,D=test,t=t1\
--dest h=192.168.2.12,P=3306,u=archiver,p=archiver,D=test,t=t1_bak \
--progress 5000 --where 'mc_id<=125' \
--statistics --charset=UTF8 --limit=10000 --txn-size 1000 --no-delete

3. 復(fù)制數(shù)據(jù)到其他mysql實(shí)例,并刪source上的舊數(shù)據(jù)(指定字符集):

/usr/bin/pt-archiver \

--source h=localhost,u=root,p=1234,P=3306,D=test,t=t1 \

--dest h=192.168.2.12,P=3306,u=archiver,p=archiver,D=test,t=t1_his \

--progress 5000 --where "CreateDate <‘2017-05-01 00:00:00‘ " \

--statistics --charset=UTF8 --limit=10000 --txn-size 1000 --bulk-delete

4. 復(fù)制數(shù)據(jù)到其他mysql實(shí)例,不刪除source數(shù)據(jù),但是使用批量插入dest上新的數(shù)據(jù)(指定字符集):

/usr/bin/pt-archiver \

--source h=localhost,u=archiver,p=archiver,P=3306,D=test,t=t1 \

--dest h=192.168.2.12,P=3306,u=archiver,p=archiver,D=test,t=t1_his \

--progress 5000 --where "c <‘2017-05-01 00:00:00‘ " \

--statistics --charset=UTF8 --limit=10000 --txn-size 1000 --no-delete  --bulk-insert

5. 導(dǎo)出數(shù)據(jù)到文件

/usr/bin/pt-archiver \

--source h=10.0.20.26,u=root,p=1234,P=3306,D=test,t=t \

--file ‘/root/test.txt‘ \

--progress 5000 --where ‘a(chǎn)<12000‘ \

--no-delete --statistics --charset=UTF8 --limit=10000 --txn-size 1000

6. 導(dǎo)出數(shù)據(jù)到文件并刪除數(shù)據(jù)庫(kù)的相關(guān)行:

/usr/bin/pt-archiver \

--source h=10.0.20.26,u=root,p=1234,P=3306,D=test,t=t \

--file ‘/root/test.txt‘ \

--progress 5000 --where ‘a(chǎn)<12000‘ \

--statistics --charset=UTF8 --limit=10000 --txn-size 1000 --purge

pt-archiver 數(shù)據(jù)刪除、遷移工具使用

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括新會(huì)網(wǎng)站建設(shè)、新會(huì)網(wǎng)站制作、新會(huì)網(wǎng)頁(yè)制作以及新會(huì)網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,新會(huì)網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到新會(huì)省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

另外有需要云服務(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)景需求。

本文題目:pt-archiver數(shù)據(jù)刪除、遷移工具使用-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://www.bm7419.com/article4/ceshie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站全網(wǎng)營(yíng)銷推廣網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)公司、標(biāo)簽優(yōu)化營(yíng)銷型網(wǎng)站建設(shè)

廣告

聲明:本網(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)

成都網(wǎng)站建設(shè)