percona之pt-table-sync介绍

功能介绍:

通过在主服务器上运行pt-table-sync,它会重建数据,数据通过复制从主服务器同步到从服务器,从而修复了一致性,在操作过程中,可以利用pt-table-checksum检查的结果。它不同步表结构、索引、或任何其他模式对象,所以在修复一致性之前需要保证他们表存在。

使用说明

shell> Usage: pt-table-sync [OPTIONS] DSN [DSN]
详情可参考
shell> pt-table-sync --help

常用参数:
--[no]bin-log:是否记录二进制日志(SET SQL_LOG_BIN=1) (defaultyes)

使用示例

# 先Master的Info,再Slave的Info
shell> pt-table-sync --replicate=test.checksums h='127.0.0.1',u='svoid',p='123qwe' 
                      h='192.168.90.129',u='svoid',p='123qwe' --print
Can't make changes on the master because no unique index exists at /usr/local/bin/pt-table-sync line 10648. 
 while doing db_test.t on 192.168.90.129
REPLACE INTO `db_test`.`user`(`user_id`, `username`, `password`) VALUES ('20', 'username20', 
'*9755A98F5E51444AB8358A17F438BAA46251A869') /*percona-toolkit src_db:db_test src_tbl:user src_dsn:h=127.0.0.1,p=...,u=svoid
dst_db:db_test dst_tbl:user dst_dsn:h=192.168.90.129,p=...,u=svoid lock:1 transaction:1 changing_src:test.checksums
replicate:test.checksums bidirectional:0 pid:3957 user:root host:rac1*/;
REPLACE INTO `db_test`.`user`(`user_id`, `username`, `password`) VALUES ('21', 'username21', 
'*17E724D2A20327629D9C7D6ADA730BCEBAA0D65C') /*percona-toolkit src_db:db_test src_tbl:user src_dsn:h=127.0.0.1,p=...,u=svoid 
dst_db:db_test dst_tbl:user dst_dsn:h=192.168.90.129,p=...,u=svoid lock:1 transaction:1 changing_src:test.checksums
replicate:test.checksums bidirectional:0 pid:3957 user:root host:rac1*/;

# 指定Slave的Info即可,结果与上面相同
shell> pt-table-sync --sync-to-master h='192.168.90.129',u='svoid',p='123qwe' --replicate=test.checksums --print
Can't make changes on the master because no unique index exists at /usr/local/bin/pt-table-sync line 10648.  
while doing db_test.t on 192.168.90.129
REPLACE INTO `db_test`.`user`(`user_id`, `username`, `password`) VALUES ('20', 'username20', 
'*9755A98F5E51444AB8358A17F438BAA46251A869') /*percona-toolkit src_db:db_test src_tbl:user src_dsn:h=127.0.0.1,p=...,u=svoid
dst_db:db_test dst_tbl:user dst_dsn:h=192.168.90.129,p=...,u=svoid lock:1 transaction:1 changing_src:test.checksums
replicate:test.checksums bidirectional:0 pid:3957 user:root host:rac1*/;
REPLACE INTO `db_test`.`user`(`user_id`, `username`, `password`) VALUES ('21', 'username21', 
'*17E724D2A20327629D9C7D6ADA730BCEBAA0D65C') /*percona-toolkit src_db:db_test src_tbl:user src_dsn:h=127.0.0.1,p=...,u=svoid 
dst_db:db_test dst_tbl:user dst_dsn:h=192.168.90.129,p=...,u=svoid lock:1 transaction:1 changing_src:test.checksums
replicate:test.checksums bidirectional:0 pid:3957 user:root host:rac1*/;

通过(--print)可以打印出来修复数据的sql语句,可以手动的去从库执行,让他们数据保持一致性。也可以通过(--execute)直接执行。


# 直接从库同步数据
shell> pt-table-sync --replicate=test.checksums h='127.0.0.1',u='svoid',p='123qwe' 
                      h='192.168.90.129',u='svoid',p='123qwe' --execute
Can't make changes on the master because no unique index exists at /usr/local/bin/pt-table-sync line 10648.  
while doing db_test.t on 192.168.90.129

最好还是用--print 打印出来的好,这样就可以知道那些数据有问题,可以人为的干预下。直接执行有一定的风险,最好提前备份好数据

注意:要是表中没有唯一索引或则主键则会报错,如db_test.t未设置主键或唯一索引,不能该方式同步主从数据

整理自网络

Svoid
2015-03-18

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29733787/viewspace-1466176/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29733787/viewspace-1466176/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值