Repair a broken replica: 1062 / 1032 row conflicts
MySQLReplicationCommand
-- 1) Failing worker, error and GTID
SELECT WORKER_ID, LAST_ERROR_NUMBER, LEFT(LAST_ERROR_MESSAGE, 250) AS last_error, APPLYING_TRANSACTION
FROM performance_schema.replication_applier_status_by_worker
WHERE LAST_ERROR_NUMBER <> 0;
-- 2) Shell: decode the row images of that transaction from the relay log
mysqlbinlog --base64-output=DECODE-ROWS -vv --include-gtids='af6bc361-c353-11f1-8f12-f69e63ad6c0e:11' /var/lib/mysql/db2-relay-bin.0* | grep '^###'
-- 3a) 1062 Duplicate entry: delete the extra row on the replica without binlogging
SET SESSION sql_log_bin = 0;
DELETE FROM shop.orders WHERE id = 20001;
-- 3b) 1032 Can't find record: insert the missing row from the WHERE (before image) values
INSERT INTO shop.orders (id, cust, amount, note, created) VALUES (6, 6, 9.00, 'n6', '2026-10-08 20:09:44');
SET SESSION sql_log_bin = 1;
-- 4) Start the applier and verify
START REPLICA SQL_THREAD;
SELECT SERVICE_STATE, LAST_ERROR_NUMBER FROM performance_schema.replication_applier_status_by_coordinator;What it does
Fixes the two most common row-based replication breaks (1062 duplicate key, 1032 row not found) without skipping the transaction, by bringing the replica row to the state the source expects; data consistency is preserved.
When to use it
When Replica_SQL_Running = No with error 1062 / 1032; as a proper repair instead of skipping the GTID with an empty transaction.
Caution
The fix on the replica must run with sql_log_bin=0; otherwise it creates an errant GTID that bites at failover. If super_read_only=ON, disable it temporarily and re-enable it afterwards. The before-image values assume binlog_row_image=FULL; with MINIMAL only the PK is logged and the rest of the row must be read from the source. One conflict in a table usually means there are more; after the repair compare the table with the source using pt-table-checksum. Relay log path: SELECT @@relay_log_basename;