一、从库上报错查看:
show slave status\G
Retrieved_Gtid_Set: e10c75be-5c1b-11e6-ab7c-000c296078ae:5-6 #6是出错的事务
Executed_Gtid_Set: e10c75be-5c1b-11e6-ab7c-000c296078ae:1-5 #已执行过的事务
Auto_Position: 1
二、解决1:单个跳过事务
通过设置gtid_next跳过这个出错的事务(只能跳过一个事务)
mysql> set gtid_next='e10c75be-5c1b-11e6-ab7c-000c296078ae:6';
mysql> begin;
mysql> commit;
mysql> set gtid_next='AUTOMATIC';
mysql> start slave;
三、解决2:批量的跳过事务
通过设置gtid_purged完成批量跳过事务
1:主库操作(查看主库上已执行的事务)
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------------------------------+
| binlog.000001 | 2364 | | | e10c75be-5c1b-11e6-ab7c-000c296078ae:1-10 |
+---------------+----------+--------------+------------------+-------------------------------------------+
1 row in set (0.00 sec)
从库上操作:
也可查看从库上已执行的事务,mysql> show master status;
mysql> reset master;
mysql> set GLOBAL gtid_purged='e10c75be-5c1b-11e6-ab7c-000c296078ae:1-10';
mysql> start slave;
四、快照恢复从库数据
https://mp.csdn.net/postedit/85238158
从库上操作:做好快照后,查看sql文件
cat db.sql | grep GTID_PURGED
SET @@GLOBAL.GTID_PURGED='e10c75be-5c1b-11e6-ab7c-000c296078ae:1-10';
mysql> reset master;
再导入sql文件
mysql> change master to master_host='主库ip', master_user='repl', master_password='repl', master_auto_position=1;
mysql> start slave;