MySQL Error 1062 (23000): Duplicate entry for key PRIMARY / UNIQUE
Row insert collided with an existing primary or unique index value.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: MySQL Error 1062 (23000)
Platform: MySQL
Common Root Causes:
- Row insert collided with an existing primary or unique index value.
Interactive Diagnostic Checklist
Verified Solutions:
- Use `INSERT ... ON DUPLICATE KEY UPDATE` or deduplicate batch loads.
Safe Diagnostic Command:
SHOW INDEX FROM <table>;
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Row insert collided with an existing primary or unique index value. Recommended diagnostic: `SHOW INDEX FROM <table>;`. Remediation: Use `INSERT ... ON DUPLICATE KEY UPDATE` or deduplicate batch loads.
Worked Examples
- Run `SHOW INDEX FROM <table>;` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-mysql-1062-duplicate-entry-key · Independently verified: 2026-11-25