What do I do if the data replication on an ApsaraDB RDS for MySQL instance is interrupted due to the setting of the unique_checks parameter?
When replication from a primary ApsaraDB RDS for MySQL instance to its secondary or read-only instance stops with Error 1062 (duplicate entry), the cause is unique_checks=0 on the primary instance. This article explains why the error occurs and how to restore replication safely.
Error message
[ERROR] [MY-010584] [Repl] Slave SQL for channel '': Worker 1 failed executing transaction 'XXX' at master log mysql-bin.XXX, end_log_pos XXX; Could not execute Write_rows_v1 event on table XXX.XXX; Duplicate entry 'XXX' for key 'xxx.xxx', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.XXX, end_log_pos XXX, Error_code: MY-001062Root cause
The unique_checks parameter is set to 0 on the primary instance.
How unique_checks works
| Value | Behavior |
|---|---|
1 (default) | ApsaraDB RDS for MySQL checks the uniqueness of the unique key in the InnoDB table |
0 | If the data managed by the DML statement is not stored in the buffer pool, ApsaraDB RDS for MySQL does not read the primary key or unique key of the disk to check the uniqueness of secondary indexes in the InnoDB table. In this case, duplicate unique keys can be inserted. However, the engine is still permitted to check for duplicates when the data is already in the buffer pool. |
Why the secondary instance catches what the primary missed
The asymmetry between primary and secondary instances triggers the interruption:
Primary instance:
unique_checks=0+ data not in the buffer pool → uniqueness check skipped → duplicate unique keys inserted and written to the binary logSecondary instance:
unique_checks=0+ data is in the buffer pool → ApsaraDB RDS for MySQL checks uniqueness of the secondary index and detects the duplicate → replication stops with Error 1062
Because buffer pool contents differ between instances at any given moment, the secondary can detect duplicates that the primary missed. This is a known MySQL behavior documented in MySQL bug #106121.
Solution
Before taking any action, verify whether the duplicate entries can be safely skipped. Run the following command on the secondary instance to inspect the replication error:
SHOW REPLICA STATUS\GCheck the Last_SQL_Error field. Confirm the error matches the HA_ERR_FOUND_DUPP_KEY / Error_code 1062 pattern shown above.
Then assess whether skipping the error is safe:
Is the transaction from a known, trusted source?
Does the duplicate entry represent real data that must be preserved on the secondary?
Was the original write on the primary intentional?
If you answer yes to any of these, do not skip the error. Reconcile the data manually before restarting replication.
If the duplicates are safe to skip (for example, bulk data import with no real conflicts)
Set unique_checks to 0 to speed up the data import.
If the duplicates may indicate real data conflicts
Set unique_checks to 1. This forces ApsaraDB RDS for MySQL to enforce unique key constraints on the primary instance, preventing duplicate entries from being written to the binary log.
Do not skip the replication error without first verifying the root cause. Bypassing uniqueness checks when real duplicates exist causes data inconsistency between the primary and secondary instances.