1588
MySQLERRORNotableData IntegrityHIGH confidence

Duplicate entry with key name

Production Risk

Low — the INSERT/UPDATE fails; no data is changed.

What this means

A duplicate entry violation occurred, and this variant includes the key name in the error message for easier identification.

Why it happens
  1. 1Inserting or updating a row with a value that already exists in a UNIQUE or PRIMARY KEY column.
How to reproduce
trigger — this will error
trigger — this will error
INSERT INTO users (email) VALUES ('duplicate@example.com');
-- when email already exists

expected output

ERROR 1588 (23000): Duplicate entry 'duplicate@example.com' for key 'users.email'

Fix

Use INSERT IGNORE or ON DUPLICATE KEY UPDATE

Use INSERT IGNORE or ON DUPLICATE KEY UPDATE
INSERT INTO users (email) VALUES ('duplicate@example.com')
ON DUPLICATE KEY UPDATE email = VALUES(email);

Why this works

Handle duplicates gracefully with ON DUPLICATE KEY UPDATE or check for existence before inserting.

Sources
Official documentation ↗

MySQL 8.0 — 1588 ER_DUP_ENTRY_WITH_KEY_NAME

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

← All MySQL errors