安裝
ubuntu安裝:
系統(tǒng)信息查看
lsb_release -a
percona-toolkit 安裝
sudo apt-get install percona-toolkit
percona-toolkit 安裝成功確認(rèn)
pt-archiver --help
目標(biāo)數(shù)據(jù)源創(chuàng)建表
步驟省略
創(chuàng)建專門的用戶
CREATE USER 'ptarchiver'@'%' IDENTIFIED BY '密碼';
GRANT ALL ON *.* TO 'ptarchiver'@'%';
FLUSH PRIVILEGES;
數(shù)據(jù)歸檔
不刪除源數(shù)據(jù)
pt-archiver --source h=source_ip,P=3306,u=ptarchiver,p=密碼,D=source_database,t=source_table --dest h=dest_ip,P=3306,u=ptarchiver,p=密碼,D=dest_database,t=dest_table --where "1=1" --statistics --no-delete
刪除源數(shù)據(jù)并批量執(zhí)行[需要設(shè)置:SET GLOBAL local_infile = 'ON'], 增加了L=ON 和 --charset=utf8
pt-archiver --source h=source_ip,P=3306,u=ptarchiver,p=密碼,D=order_center_test,t=t_order_source,L=ON --dest h=dest_ip,P=3306,u=ptarchiver,p=密碼,D=dest_database,t=dest_table,L=ON --where "1=1" --statistics --no-delete --limit 1000 --commit-each --bulk-insert --charset=utf8
批量刪除參數(shù):--bulk-delete
參考文章:
MySQL 歸檔數(shù)據(jù)的方法你知道了嗎
pt-archiver 命令
pt-archiver官網(wǎng)