0
0
MySQLquery~5 mins

Deadlock detection and prevention in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a deadlock in a database?
A deadlock happens when two or more transactions wait for each other to release locks, so none can proceed. It's like two people blocking each other in a narrow hallway.
Click to reveal answer
intermediate
How does MySQL detect deadlocks?
MySQL detects deadlocks by checking for cycles in the lock wait graph. When it finds a cycle, it chooses one transaction to roll back to break the deadlock.
Click to reveal answer
beginner
Name one common method to prevent deadlocks.
One common method is to always acquire locks in the same order in all transactions. This avoids circular waiting and prevents deadlocks.
Click to reveal answer
intermediate
What is the role of InnoDB in deadlock handling in MySQL?
InnoDB storage engine automatically detects deadlocks and rolls back one transaction to resolve it, allowing others to continue.
Click to reveal answer
beginner
Why is it important to keep transactions short to prevent deadlocks?
Short transactions hold locks for less time, reducing the chance that other transactions will wait and cause deadlocks.
Click to reveal answer
What causes a deadlock in a database?
AA database backup running
BA transaction running too fast
CA query with syntax error
DTwo transactions waiting on each other’s locks
How does MySQL resolve a detected deadlock?
AIt ignores the deadlock
BIt rolls back one transaction to break the deadlock
CIt restarts the database server
DIt pauses all transactions
Which practice helps prevent deadlocks?
AAcquiring locks in a consistent order
BRunning transactions without locks
CUsing very large transactions
DIgnoring error messages
What does InnoDB do when it detects a deadlock?
ARolls back one transaction automatically
BShuts down the database
CSends an email alert
DLocks all tables
Why should transactions be kept short to avoid deadlocks?
AShort transactions increase deadlocks
BShort transactions use more CPU
CShort transactions hold locks less time, reducing conflicts
DShort transactions slow down queries
Explain what a deadlock is and how MySQL detects and resolves it.
Think about transactions waiting for each other and how MySQL breaks the cycle.
You got /3 concepts.
    Describe two ways to prevent deadlocks in database transactions.
    Consider how to avoid circular waiting and reduce lock time.
    You got /3 concepts.