背景
从上一篇延伸的问题是我们发现了主从的不一致
本篇将利用生成的数据来进行修复
引出本片主演 pt-table-sync
每次skip之后请及时修复数据一致
使用
使用的方式很简单
t-table-sync --sync-to-master h=10.29.30.239,u=sync,p=XXXXX --databases=f6db --print
这样可以将将要执行的sql打印出来 比如
REPLACE INTO `f6db`.`p_user`(`user_id`, `account_id`, `user_name`, `nick_name`, `user_tel`, `user_address_station`, `user_address_province`, `user_address_city`, `user_address_area`, `user_address`, `user_point`, `user_type`, `station_id`, `wx_open_id`, `wx_app_id`, `employee_id`, `memo`, `dellete_flag`, `update_user_id`, `create_user_id`, `update_date`, `create_date`, `img_src`, `group_id`, `fenxiangurl`, `isweixin`, `stationcode`, `birthday`, `f6_open_id`, `nick_name_memo`) VALUES ('455036', NULL, '隐性埋铭、', '隐性埋铭、', NULL, NULL, NULL, NULL, NULL, NULL, NULL, '3', '1882', 'oaY3Ms60Z_CGZ7JQgiUOuYrywCZU', 'wxb75ae9b3b266ea2d', NULL, NULL, '0', NULL, NULL, '2017-08-01 00:32:02', '2017-08-01 00:32:02', 'http://thirdwx.qlogo.cn/mmopen/Q3waI3icINT9HMULclddzXQqyjv5cBcnQ59gEZWsoOpqNBgqUicIicnKAKDDNKLZs1BwbrKzntH7tN6DPUsq8fjft5pYMAgcYdy/132', '0', NULL, NULL, NULL, NULL, NULL, NULL) /*percona-toolkit src_db:f6db src_tbl:p_user src_dsn:P=3306,h=10.25.24.197,p=...,u=sync dst_db:f6db dst_tbl:p_user dst_dsn:h=10.27.156.174,p=...,u=sync lock:1 transaction:1 changing_src:1 replicate:0 bidirectional:0 pid:20542 user:root host:iZuf6aj63ajpklcizngg6kZ*/;
原理很简单 通过replace into 在主库上更新 这样主库不会发生更新而错误的从库将会发生更新【前提是惟一键(或者主键)】
如果需要执行对应的sql 则将print改成execute
pt-table-sync --sync-to-master h=10.29.30.239,u=sync,p=XXXXX --databases=f6db --execute
执行完毕后重新执行checksum
pt-table-checksum --create-replicate-table --nocheck-replication-filters --ignore-tables-regex=tm_monitor.* h=10.25.24.197,u=CHECKSUM,p=XXXXX,P=3306 --no-check-binlog-format --databases=d6db
对应的从库中执行如下sql
SELECT db, tbl, SUM(this_cnt) AS total_rows, COUNT(
*
) AS chunks
FROM percona.checksums
WHERE (
master_cnt <> this_cnt
OR master_crc <> this_crc
OR ISNULL(master_crc) <> ISNULL(this_crc))
GROUP BY db, tbl;
将会发现数据差异已经消失 即为主从同步
至于为嘛这个数据更新不掉……【因为有些表没有惟一键!!!对我说的就是没有主键!!!】