Reference · Cheat sheet
The one-page compressed essence: locks sit on index records; writes and locking-reads take them; cycles deadlock.
InnoDB locks index records, always. Which rows lock depends on which index
the query walks — so an unindexed WHERE locks everything it scans.
| Lock | Covers | Stops |
|---|---|---|
| record | one index record | update/delete of that row |
| gap | gap between records (or before first / after last) | inserts into the gap |
| next-key | record + gap before it | both — default for scans in RR |
| plain SELECT | no locks — MVCC snapshot (0005) |
| SELECT … FOR SHARE | S (shared) — others can read, not write |
| SELECT … FOR UPDATE | X (exclusive) — as if updating |
| UPDATE / DELETE | X (exclusive) on rows walked |
1213 and retry the txn.WHERE columns of UPDATE/FOR UPDATE.SHOW ENGINE INNODB STATUS\G → LATEST DETECTED DEADLOCK
(held vs waited-for locks, and the SQL of each txn).Source: MySQL 8.0 Manual — InnoDB Locking · Deadlocks in InnoDB · All lessons