MySQL error 1213: Deadlock found when trying to get lock
InnoDB detected transactions waiting on each other’s locks and rolled back one transaction so the others could proceed.
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transactionWhat MySQL error 1213 means
Section titled “What MySQL error 1213 means”A cycle of lock waits prevented the transactions from progressing. Common causes include updates to shared rows in different orders, long transactions, and queries that lock more rows than necessary.
A deadlock is different from a query that is still waiting. MySQL has already chosen a transaction to roll back when it reports this error.
Recover the transaction
Section titled “Recover the transaction”- Read the failed operation’s transaction outcome in TableAI.
- Check that repeating the complete operation is appropriate.
- Retry the entire transaction after a short delay.
InnoDB rolls back the entire transaction for a deadlock, so retrying only its final statement omits earlier work. See MySQL’s transaction error handling.
For staged grid changes, use edit rejected to review the database cause before another Apply.
Investigate repeated deadlocks
Section titled “Investigate repeated deadlocks”On a local server or Docker, inspect the latest InnoDB deadlock:
SHOW ENGINE INNODB STATUS;This command requires PROCESS. Its output can contain SQL and private values; redact those before sharing diagnostics.
For a cloud or company server, ask the administrator for the deadlock details if you cannot read them. Include the database, error code, failure time, and a redacted description of the transaction order.
Use the evidence to choose a change:
- Access shared rows in the same order across transactions.
- Keep transactions short.
- Review indexes and query plans to reduce unnecessary row locking.
- Divide large writes into smaller transactions when the data rules permit it.
How TableAI shows it
Section titled “How TableAI shows it”TableAI labels code 1213 Deadlock Detected. Its recovery hint recommends a transaction retry and consistent row order.
View locks shows current waits, so a resolved deadlock may no longer appear there. Use write and run SQL for diagnostic queries, or slow queries and timeouts for other delays.
Return to the MySQL overview for related tasks.