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

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

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

2. 常用參數(shù)

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

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

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

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

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

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

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

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設