3133
MariaDBERRORNotableConstraintsHIGH confidence

Duplicate value in index but value is unknown

Production Risk

Medium — duplicate key errors indicate data integrity issues.

What this means

A unique index violation was detected but the duplicate value cannot be shown, typically because the column uses a type or collation that obscures the duplicate in the error message.

Why it happens
  1. 1Inserting or updating a row that would create a duplicate in a unique or primary key index.
  2. 2The value cannot be displayed (e.g., binary or encrypted column).
How to reproduce
trigger — this will error
trigger — this will error
INSERT INTO t1 (id) VALUES (1), (1);

expected output

ERROR 3133 (23000): Duplicate entry for key 'PRIMARY'.

Fix 1

Identify and remove duplicate rows before inserting

Identify and remove duplicate rows before inserting
SELECT col, COUNT(*) FROM t1 GROUP BY col HAVING COUNT(*) > 1;

Why this works

Locates existing duplicates so they can be resolved.

Fix 2

Use INSERT IGNORE or ON DUPLICATE KEY UPDATE

Use INSERT IGNORE or ON DUPLICATE KEY UPDATE
INSERT IGNORE INTO t1 (id) VALUES (1);

Why this works

Silently skips the duplicate row insertion.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3133 ER_DUP_UNKNOWN_IN_INDEX2

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

← All MariaDB errors