主从是非gtid模式,查看状态显示1062错误,导致这类错误的原因大概就是有重复数据,无法完成数据的新增,解决办法是可以跳过这个错误,或者你知道导致的重复的语句可以将这个语句删掉让他自动同步创建,这里演示跳过这个错误的方式,因为语句太多了,也不知道什么时候断开的同步,查看具体的报错信息
mysql> select * from performance_schema.replication_applier_status_by_worker\G;
*************************** 1. row ***************************
CHANNEL_NAME:
WORKER_ID: 1
THREAD_ID: NULL
SERVICE_STATE: OFF
LAST_ERROR_NUMBER: 1062
LAST_ERROR_MESSAGE: Worker 1 failed executing transaction 'ANONYMOUS' at source log mysql-bin.000541, end_log_pos 766231692; Could not execute Write_rows event on table exclusive-cloud.cms_repository_resource; Duplicate entry '2f3cec50f924e5a4b3423f061e8e767d1708750197372' for key 'cms_repository_resource.uk_file_identifier', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event'ssource log mysql-bin.000541, end_log_pos 766231692
LAST_ERROR_TIMESTAMP: 2024-06-02 01:41:08.349379
LAST_APPLIED_TRANSACTION: ANONYMOUS
LAST_APPLIED_TRANSACTION_ORIGINAL_COMMIT_TIMESTAMP: 2024-06-01 11:54:56.639723
LAST_APPLIED_TRANSACTION_IMMEDIATE_COMMIT_TIMESTAMP: 2024-06-01 11:54:56.639723
LAST_APPLIED_TRANSACTION_START_APPLY_TIMESTAMP: 2024-06-02 01:41:08.342683
LAST_APPLIED_TRANSACTION_END_APPLY_TIMESTAMP: 2024-06-02 01:41:08.345292
mysql> stop slave;
mysql> set global sql_slave_skip_counter=1;
mysql> start slave;
mysql> show slave status\G;
如果像这样的错误比较多可以将1062错误写在配置文件中全部跳过
# 修改my.cnf配置文件,在[mysqld]段加入
[mysqld]
slave_skip_errors = 1062