# tar -zxvf percona-toolkit-2.2.17.tar.gz
# yum -y install perl perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes perl-TermReadKey
# yum -y install perl-Digest-MD5
[root@linuxidc bin]# pwd
/data/soft/percona-toolkit-2.2.17/bin
pt-archiver--将表数据归档到另一个表或文件中
删除或归档一张大表,导出文件等,可以进行主从同步数据
[mysql@mysqlt1 bin]$ ./pt-archiver --help
Archive all rows from oltp_server to olap_server and to a file:
pt-archiver --source h=oltp_server,D=test,t=tbl --dest h=olap_server \
--file '/var/log/archive/%Y-%m-%d-%D.%t' \
--where "1=1" --limit 1000 --commit-each
Purge (delete) orphan rows from child table:
pt-archiver --source h=host,D=db,t=child --purge \
--where 'NOT EXISTS(SELECT * FROM parent WHERE col=child.col)'
参数说明:注意:至少需要指定--dest,--file,--purge 其中的一个
--ignore and --replace are mutually exclusive.
--txn-size and --commit-each are mutually exclusive.
--low-priority-insert and --delayed-insert are mutually exclusive.
--share-lock and --for-update are mutually exclusive.
--analyze and --optimize are mutually exclusive.
--no-ascend and --no-delete are mutually exclusive.
--source :指定要归档表的信息,兼容DSN选项
--source h=my_server,D=my_database,t=my_tbl
b:如果为true,则使用SQL_LOG_BIN禁用binlog--If true, disable binlog with SQL_LOG_BIN.
i:进行操作时,被指定使用的索引 --Index to use.
h=host,D=database,t=table,u=user,p=password,P=port,S=socket
A:Default character set
L:Explicitly enable LOAD DATA LOCAL INFILE.
m:Plugin module name
--source D=test,t=test1,m=My::Module1 --dest m=My::Module2,t=test2
--analyze:Run ANALYZE TABLE afterwards on --source and/or --dest ###--analyze=ds
--ascend-first:Ascend only first column of index ###升序索引优化,提供最左索引(多列主键)的升序。
--no-ascend:Do not use ascending index optimization.
--ask-pass:Prompt for a password when connecting to MySQL. ##连接mysql时输入密码
--buffer:缓冲区输出到--file并在提交时刷新,每次事务提交禁止刷写到磁盘,有操作系统决定刷写。该参数可以提高刷写到文件的性能,但崩溃可能会有数据丢失。
--commit-each:Commit each set of fetched and archived rows (disables --txn-size).##控制事务大小,每次提取、归档就提交。禁用--txn-size
--config:以逗号分隔的配置文件列表; 如果指定,则必须是命令行上的第一个选项
--delayed-insert:Add the DELAYED modifier to INSERT statements##在insert后面添加delayed,延迟写入
--dry-run: Print queries and exit without doing anything##打印查询并退出而不做任何事情
--file:File to archive to,