设为首页 加入收藏

TOP

MySQL归档 pt-archiver 工具(一)
2019-04-01 00:09:01 】 浏览:424
Tags:MySQL 归档 pt-archiver 工具

# 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, with DATE_FORMAT()-like formatting
%d Day of the month, numeric (01..31)
%H Hour (00..23)
%i Minutes, numeric (00..59)
%m Month, numeric (01..12)
%s Seconds (00..59)
%Y Year, numeric, four digits
%D Database name
%t Table name
Example:-file '/var/log/archive/%Y-%m-%d-%D.%t'
--for-update:Adds the FOR UPDATE modifier to SELECT statements.
--ignore:insert语句加入ignore
--no-delete:不要删除存档的行,默认会删除。不允许--no-ascend,因为启用它们都会导致无限循环。
--progress:每多少行打印进度信息:打印当前时间,已用时间以及每X行存档的行数
--purge:清除而不是归档; 允许省略--file和--dest。如果只想清除行,请考虑使用--primary-key-only指定表的主键列。 这样可以防止无缘无故地从服务器获取所有列
--quick-delete:delete语句里添加quick
--replace:replace into代替insert into
--statistics:收集并打印时间统计信息
--txn-size:每个事务的行数,默认1。指定每个事务的大小(行数)。0完全禁用事务。在pt-archiver处理这么多行之后,如果指定该参数,它会提交--source和--dest,并刷新--file给出的文件。
--where:指定WHERE子句以限制存档的行。 子句里不要包含单词WHERE,不需要WHERE子句,请使用--where 1=1。如
--where 'ts < current_date - interval 90 day'
--limit:限制检索要归档的行的SELECT语句返回的行数,默认是1。这可能会导致与其他查询的更多争用,具体取决于存储引擎,事务隔离级别和--for-update等选项。
--bulk-delete:使用单个DELETE语句批量删除每个行块。该语句删除块的第一行和最后一行之间的每一行,隐含--commit-each.批量删除source上的旧数据
--bulk-insert:批量插入数据到dest主机
--

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于Oracle单行函数与多行函数 下一篇Oracle 利用执行计划来避免排序操..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目