MySQL Error 1213 (40001): Deadlock found when trying to get lock
Concurrent InnoDB gap/row locks formed a cycle and InnoDB rolled back the smaller transaction.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: MySQL Error 1213 (40001)
Platform: MySQL
Common Root Causes:
- Concurrent InnoDB gap/row locks formed a cycle and InnoDB rolled back the smaller transaction.
Interactive Diagnostic Checklist
Verified Solutions:
- Order updates consistently, add proper indexes to shrink gap locks, and retry error 1213.
Safe Diagnostic Command:
SHOW ENGINE INNODB STATUS\G
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Concurrent InnoDB gap/row locks formed a cycle and InnoDB rolled back the smaller transaction. Recommended diagnostic: `SHOW ENGINE INNODB STATUS\G`. Remediation: Order updates consistently, add proper indexes to shrink gap locks, and retry error 1213.
Worked Examples
- Run `SHOW ENGINE INNODB STATUS\G` 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-1213-innodb-deadlock · Independently verified: 2026-11-25