pt-archiver 数据删除、迁移工具使用

发布时间:2020-06-10 18:35:29 作者:AndyMac
来源:网络 阅读:19463

1. 数据库连接参数

参数 说明
A 字符编码
D
F 从文件读取选项
L 加载数据本地文件
P 端口
S socket文件
a 执行查询的数据库
b 如果是true, 禁用SQL_LOG_BIN
h 数据库地址
i 查询使用的索引
m 插件模块名称
p 数据库密码
t
u 用户名

2. 常用参数

参数 默认值 说明
--limit 10000 每次取1000行数据用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 输出执行过程及最后的操作统计
--charset=UTF8 指定字符集为UTF8
--bulk-delete 批量删除source上的旧数据(例如每次1000行的批量删除操作)
--bulk-insert 批量插入数据到dest主机 (看dest的general log发现它是通过在dest主机上LOAD DATA LOCAL INFILE插入数据的)
--replace 将insert into 语句改成replace写入到dest库
--sleep 120 每次归档了limit个行记录后的休眠120秒(单位为秒)
--file '/root/test.txt' 导出的文件路径
--purge 删除source数据库的相关匹配记录
--header 输入列名称到首行(和--file一起使用)
-no-check-charset 不指定字符集
--check-columns 检验dest和source的表结构是否一致,不一致自动拒绝执行(不加这个参数也行。默认就是执行检查的)
--no-check-columns 不检验dest和source的表结构是否一致,不一致也执行(会导致dest上的无法与source匹配的列值被置为null或者0)
--chekc-interval 默认1s检查一次
--local 不把optimize或analyze操作写入到binlog里面(防止造成主从延迟巨大)
--retries 超时或者出现死锁的话,pt-archiver进行重试的间隔(默认1s)
--no-version-check 目前为止,发现部分pt工具对阿里云RDS操作必须加这个参数
--analyze=ds 操作结束后,优化表空间(d表示dest,s表示source)

2. example

1. 删除老数据

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

2. 复制数据到其他mysql实例,且不删除source的数据(指定字符集):

/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. 复制数据到其他mysql实例,并删source上的旧数据(指定字符集):

/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. 复制数据到其他mysql实例,不删除source数据,但是使用批量插入dest上新的数据(指定字符集):

/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. 导出数据到文件

/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<12000‘ \

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

6. 导出数据到文件并删除数据库的相关行:

/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<12000‘ \

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

pt-archiver 数据删除、迁移工具使用

推荐阅读:
  1. pt-duplicate-key-checker及pt-diskstats及pt-deadlock-
  2. Percona pt-archiver重构版--大表数据归档工具

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

percona 数据 迁移工具

上一篇:spark本地运行模式

下一篇:linux中的分区和目录

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》