现象
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.3.89
Master_User: slaveuser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000085
Read_Master_Log_Pos: 317776
Relay_Log_File: qfc-ntp-relay-bin.000168
Relay_Log_Pos: 2846473
Relay_Master_Log_File: mysql-bin.000084
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1062
Last_Error: Error 'Duplicate entry '29162-1629680400' for key 'trends.PRIMARY'' on query. Default database: 'zabbix'. Query: 'insert into trends (itemid,clock,num,value_min,value_avg,value_max) values (29162,1629680400,60,0.42563800000000002,0.57876106666666671,3.3019660000000002)'
Skip_Counter: 0
Exec_Master_Log_Pos: 8151180
Relay_Log_Space: 4221467
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry '29162-1629680400' for key 'trends.PRIMARY'' on query. Default database: 'zabbix'. Query: 'insert into trends (itemid,clock,num,value_min,value_avg,value_max) values (29162,1629680400,60,0.42563800000000002,0.57876106666666671,3.3019660000000002)'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: dd79ee38-d7fd-11eb-95e2-0cda411d3f33
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 210824 14:10:56
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
解决方案:
1062:主键冲突 Duplicate entry ‘%s’ for key %d
再my.cnf的[mysqld]增加一条:
slave-skip-errors = 1062
重启备机恢复
详细参考:https://blog.csdn.net/coco3600/article/details/100232783