1724
MySQLWARNINGNotableReplicationHIGH confidence

Unsafe statement: INSERT into table with two or more unique keys

Production Risk

Medium — data may diverge on the replica.

What this means

An INSERT or REPLACE into a table with two or more unique keys is unsafe for statement-based replication because on-duplicate-key handling may be non-deterministic.

Why it happens
  1. 1Table has multiple UNIQUE indexes and an INSERT ... ON DUPLICATE KEY UPDATE is executed in STATEMENT mode.
How to reproduce
trigger — this will error
trigger — this will error
INSERT INTO t (a, b, c) VALUES (1, 2, 3) ON DUPLICATE KEY UPDATE c = c + 1;

expected output

Warning (Code 1724): Unsafe statement written to binary log using statement format. Statement is unsafe because the table has two or more unique keys.

Fix

Use ROW-based replication

Use ROW-based replication
SET GLOBAL binlog_format = 'ROW';

Why this works

ROW format captures the exact rows affected, resolving non-determinism from multiple unique keys.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1724 ER_BINLOG_UNSAFE_INSERT_TWO_KEYS

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors