溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

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

發(fā)布時(shí)間:2020-06-10 18:35:29 來(lái)源:網(wǎng)絡(luò) 閱讀:19481 作者:AndyMac 欄目:MySQL數(shù)據(jù)庫(kù)

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

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

2. 常用參數(shù)

參數(shù) 默認(rèn)值 說(shuō)明
--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í)行過(guò)程及最后的操作統(tǒng)計(jì)
--charset=UTF8 指定字符集為UTF8
--bulk-delete 批量刪除source上的舊數(shù)據(jù)(例如每次1000行的批量刪除操作)
--bulk-insert 批量插入數(shù)據(jù)到dest主機(jī) (看dest的general log發(fā)現(xiàn)它是通過(guò)在dest主機(jī)上LOAD DATA LOCAL INFILE插入數(shù)據(jù)的)
--replace 將insert into 語(yǔ)句改成replace寫(xiě)入到dest庫(kù)
--sleep 120 每次歸檔了limit個(gè)行記錄后的休眠120秒(單位為秒)
--file '/root/test.txt' 導(dǎo)出的文件路徑
--purge 刪除source數(shù)據(jù)庫(kù)的相關(guān)匹配記錄
--header 輸入列名稱(chēng)到首行(和--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上的無(wú)法與source匹配的列值被置為null或者0)
--chekc-interval 默認(rèn)1s檢查一次
--local 不把optimize或analyze操作寫(xiě)入到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ù)刪除、遷移工具使用

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI