MySQL & InnoDB (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What are Deadlocks in MySQL and how do you troubleshoot them?
senior LevelDatabases & SQLMySQL
In Simple Words: A deadlock occurs when two or more transactions hold locks that the other needs, creating a circular dependency:
- Example: Transaction 1 locks Row A and requests Row B; Transaction 2 locks Row B and requests Row A.
- InnoDB Detection: InnoDB runs a background wait-for graph cycle detector. When a deadlock occurs, it automatically aborts and rolls back the transaction with the smallest undo log footprint.
- Inspection: Run
SHOW ENGINE INNODB STATUS;and inspect theLATEST DETECTED DEADLOCKsection.