Glossary

Deadlock

A deadlock is a situation in a database or multi-threaded code where two processes are waiting for each other and neither can proceed. Transaction A has locked resource 1 and is waiting for resource 2; transaction B has done the opposite.

How it occurs

Classic example: transferring money. Transaction A locks account 1, then tries to lock account 2. Transaction B has locked account 2 and is waiting for account 1. Both wait forever.

How the DBMS resolves it

MySQL and other databases automatically detect deadlocks and "kill" one of the transactions (the one with fewer changes). That transaction ends with an error and must be retried by the application.

Prevention