1.pt-archiver
1.1 pt-archive是啥
属于大名鼎鼎的percona工具集的一员,是归档MySQL大表数据的最佳轻量级工具之一。
注意,相当轻,相当方便简单。
1.2 pt-archive能干啥
清理线上过期数据;
导出线上数据,到线下数据作处理;
清理过期数据,并把数据归档到本地归档表中,或者远端归档服务器。
操作过程:
1.安装percona-toolkit数据包
直接从官方下载RPM数据包然后yum localinstall 进行本地安装,安装后直接可以使用
下载地址:https://www.percona.com/downloads/percona-toolkit/3.1.0/binary/redhat/7/x86_64/percona-toolkit-3.1.0-2.el7.x86_64.rpm
yum -y localinstall percona-toolkit-3.1.0-2.el7.x86_64.rpm
1.3实例1:
任务:将多实例的10.0.0.51服务器中3306端口数据库中的student表中的数据归档导入到10.0.0.51服务器3307端口数据库的同名表中。
pt-archiver --source h=10.0.0.51,P=3306,u=test,p='123456',D=oldboyedu,t=student --dest h=10.0.0.51,P=3307,u=test,p='123',D=test,t=student --charset=UTF8mb4 --where 'xid<5' --progress 10000 --limit=10000 --statistics --no-delete --no-version-check
--charset=UTF8mb4 指定表的字符集
--where 'xid<5' 指定范围
--progress 10000 指定最大范围
--limit=10000 指定最大大小
--statistics 统计归档
--no-delete 不删除源数据
--no-version-check 不进行版本检查
1.3实例2:
任务:将多实例的10.0.0.51服务器中3306端口数据库中的student表中的数据归档导出到本地家目录下
pt-archiver --source h=10.0.0.51,P=3306,u=test,p='123456',D=oldboyedu,t=student --file '/root/2.log' --where "xid<100" --no-check-charset --no-delete --charset=utf8
--file 指定保存的文件目录
--where 指定导出表的范围
--no-check-charset 指定不进行检查字符集
--no-delete 不删除原表
--charset=utf8 指定导出的字符集