双主架构双向复制
由于历史数据原因导致部分数据不同步,删除无效的数据另一个从库直接报错
Last_Error: Could not execute Delete_rows event on table yun_sche.yun_table; Can't find record in 'yun_table', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000001, end_log_pos 4966
Last_SQL_Error: Could not execute Delete_rows event on table yun_sche.yun_table; Can't find record in 'yun_table', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000001, end_log_pos 4966
处理方案
登录从数据库,查看处理状态
show slave status\G
摘取有效信息
Retrieved_Gtid_Set: 6e40329e-3a1f-11f0-baa5-fa163e4fa9f0:7-16
Executed_Gtid_Set: 6e40329e-3a1f-11f0-baa5-fa163e4fa9f0:1-14,
cae2ebb6-3a99-11f0-9962-0242ac110003:1-7
数据说明:
Retrieved_Gtid_Set已获取的GTID集合
表示从库 I/O 线程已经从主库的二进制日志中接收到(拉取)的所有事务的 GTID 集合,这些事务已经写入到从库的 relay log 中,但尚未全部执行.由 slave I/O 线程维护,只增不减(除非重置复制),表示从库"知道"的所有事务
6e40329e-3a1f-11f0-baa5-fa163e4fa9f0:7-16 表示从6e40329e-3a1f-11f0-baa5-fa163e4fa9f0接收了事务7-16
Executed_Gtid_Set已执行的GTID集合
表示从库 SQL 线程已经执行完成的所有事务的 GTID 集合,包括从主库复制来的事务和从库本地产生的事务
6e40329e-3a1f-11f0-baa5-fa163e4fa9f0:1-14,cae2ebb6-3a99-11f0-9962-0242ac110003:1-7表示执行了6e40329e-3a1f-11f0-baa5-fa163e4fa9f0中1-14的数据,卡在了15,执行了本地cae2ebb6-3a99-11f0-9962-0242ac110003的1-7。
处理错误
# 卡在了15,因为是需要删除的数据可以直接跳过
mysql> STOP SLAVE;
Query OK, 0 rows affected (0.01 sec)
mysql> SET GTID_NEXT = '6e40329e-3a1f-11f0-baa5-fa163e4fa9f0:15';
Query OK, 0 rows affected (0.00 sec)
mysql> BEGIN; COMMIT;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> SET GTID_NEXT = 'AUTOMATIC';
Query OK, 0 rows affected (0.00 sec)
mysql> START SLAVE;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 121.36.71.28
Master_User: docker_config
Master_Port: 33070
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 5584
Relay_Log_File: e1cf51efec7f-relay-bin.000009
Relay_Log_Pos: 454
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes