原因:
因调整服务器架构,需加多一台数据库从库,在同步时提示主键错误.
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.130.69.23
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.005600
Read_Master_Log_Pos: 12635460
Relay_Log_File: SL-sasha-db-3-relay-bin.000002
Relay_Log_Pos: 1120
Relay_Master_Log_File: master-bin.005599
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: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '1fbad120-2835-11e8-964c-7e2eab976d2f:1323355863' at master log master-bin.005599, end_log_pos 2297. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Skip_Counter: 0
Exec_Master_Log_Pos: 961
Relay_Log_Space: 281080188
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: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '1fbad120-2835-11e8-964c-7e2eab976d2f:1323355863' at master log master-bin.005599, end_log_pos 2297. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 1fbad120-2835-11e8-964c-7e2eab976d2f
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: 191008 10:05:35
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 1fbad120-2835-11e8-964c-7e2eab976d2f:1323355859-1323817955
Executed_Gtid_Set: 1fbad120-2835-11e8-964c-7e2eab976d2f:1-1323355862
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
按照从库的提示查找原因
说明:有时会提示insert delect 这些操作的错误,那么就需要核对主库 和从库 是否存在某条数据,核对没问题方可加入slave_skip_errors = 1062
mysql> select * from performance_schema.replication_applier_status_by_worker\G
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 37
Current database: *** NONE ***
*************************** 1. row ***************************
CHANNEL_NAME:
WORKER_ID: 1
THREAD_ID: 27
SERVICE_STATE: ON
LAST_SEEN_TRANSACTION: 1fbad120-2835-11e8-964c-7e2eab976d2f:1323840210
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
*************************** 2. row ***************************
CHANNEL_NAME:
WORKER_ID: 2
THREAD_ID: 28
SERVICE_STATE: ON
LAST_SEEN_TRANSACTION: 1fbad120-2835-11e8-964c-7e2eab976d2f:1323840086
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
*************************** 3. row ***************************
CHANNEL_NAME:
WORKER_ID: 3
THREAD_ID: 29
SERVICE_STATE: ON
LAST_SEEN_TRANSACTION: 1fbad120-2835-11e8-964c-7e2eab976d2f:1323839341
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
*************************** 4. row ***************************
CHANNEL_NAME:
WORKER_ID: 4
THREAD_ID: 30
SERVICE_STATE: ON
LAST_SEEN_TRANSACTION: 1fbad120-2835-11e8-964c-7e2eab976d2f:1323832891
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
解决:
$ vim /etc/my.cnf
加入:
slave_skip_errors = 1062
#重启生效
$ service mysqld restart