pt-table-sync:对两个库不一致的数据进行同步,他能够自动发现两个实例间不一致的数据,然后进行sync操作,pt-table-sync无法同步表结构,和索引等对象,只能同步数据
一、表没有主键
--print
./pt-table-sync --ignore-databases=mysql,sys --no-check-slave dsn=u=checkq,p=123456,h=192.168.56.108,P=3306 dsn=u=checkq,p=123456,h=192.168.56.101,P=3306 --databases=bhs --tables=pp --print
INSERT INTO bhs
.pp
(id
, name
) VALUES ('1', 'ee') /percona-toolkit src_db:bhs src_tbl:pp src_dsn:P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:pp dst_dsn:P=3306,h=192.168.56.101,p=...,u=checkq lock:0 transaction:1 changing_src:0 replicate:0 bidirectional:0 pid:3704 user:root host:managed/;
--execute
./pt-table-sync --ignore-databases=mysql,sys --no-check-slave h=192.168.56.108,u=checkq,p=123456,P=3306 h=192.168.56.101,u=checkq,p=123456,P=3306 --databases=bhs --tables=pp --execute --print
INSERT INTO bhs
.pp
(id
, name
) VALUES ('1', 'ee') /percona-toolkit src_db:bhs src_tbl:pp src_dsn:P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:pp dst_dsn:P=3306,h=192.168.56.101,p=...,u=checkq lock:0 transaction:1 changing_src:0 replicate:0 bidirectional:0 pid:3747 user:root host:managed/;
二、表有主键
--print
./pt-table-sync --sync-to-master --charset=utf8 --ignore-databases=mysql,sys --no-check-slave h=192.168.56.101,u=checkq,p=123456,P=3306 --databases=bhs --tables=test --print
REPLACE INTO bhs
.test
(id
, name
) VALUES ('3', 'd') /percona-toolkit src_db:bhs src_tbl:test src_dsn:A=utf8,P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:test dst_dsn:A=utf8,P=3306,h=192.168.56.101,p=...,u=checkq lock:1 transaction:1 changing_src:1 replicate:0 bidirectional:0 pid:3768 user:root host:managed/;
./pt-table-sync --execute --sync-to-master --charset=utf8 --ignore-databases=mysql,sys --no-check-slave h=192.168.56.101,u=checkq,p=123456,P=3306 --databases=bhs --tables=test --print
REPLACE INTO bhs
.test
(id
, name
) VALUES ('3', 'd') /percona-toolkit src_db:bhs src_tbl:test src_dsn:A=utf8,P=3306,h=192.168.56.108,p=...,u=checkq dst_db:bhs dst_tbl:test dst_dsn:A=utf8,P=3306,h=192.168.56.101,p=...,u=checkq lock:1 transaction:1 changing_src:1 replicate:0 bidirectional:0 pid:3775 user:root host:managed/;