How to Fix MySQL Error 1205 (ER_LOCK_WAIT_TIMEOUT)
You get mysql error 1205 when a query waits too long for a row lock. You fix it by ending the blocking session or making your database updates smaller. When this happens, the database returns the message Lock wait timeout exceeded; try restarting transaction. This issue uses SQLSTATE HY000 and the error symbol ER_LOCK_WAIT_TIMEOUT in your logs. It means one session holds a lock while another session waits in line. If the timer runs out first, the waiting query fails right away. What causes my
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get mysql error 1205 when a query waits too long for a row lock. You fix it by ending the blocking session or making your database updates smaller.
When this happens, the database returns the message Lock wait timeout exceeded; try restarting transaction. This issue uses SQLSTATE HY000 and the error symbol ER_LOCK_WAIT_TIMEOUT in your logs. It means one session holds a lock while another session waits in line. If the timer runs out first, the waiting query fails right away.
What causes mysql error 1205 in your database
Row locks protect your data when many users write to a table at once. When a session changes a row, the storage engine locks that specific record. Other sessions cannot change that same row until the first session finishes its work. If the first keeps the session active open too long, the waiting session hits the timeout limit.
Long transactions are the most common cause of this lock wait issue. An app might start a transaction and then call an slow outside service. While the app waits for a reply, the database holds those row locks open. Uncommitted manual changes from a developer session can also block live traffic for minutes.
Missing indexes make the problem much worse for your busy tables. When a query lacks a good index, the engine must scan many extra rows. The database then locks every row it scans instead of just the target rows. Bulk updates and large delete jobs also grab thousands of locks in one step. High network latency between your app and database stretches out every open transaction too.
How to find the blocking session in production
To solve the problem right now, you must find which session holds the lock. Database admins inspect the system lock tables and active process lists to see waiting queries. These system views show the exact thread ID and the query text causing the block. You can also see how many seconds the blocking transaction has been open.
Do not give every developer broad admin rights just to check these system views. Wide permissions create big risks when people rush to fix an outage. Instead, use a read role that only views process state and lock data. Once you find the stuck session, ask the owner if it is safe to stop. If an idle session holds the lock, an admin can stop that single thread.
MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to fix and prevent lock wait timeouts
Raising the lock timeout setting is rarely the right fix for your system. A longer timer only makes your app threads wait in line for more time. Instead, you should make your transactions short and fast across your whole app. Move all slow network calls and file work outside of the database transaction block.
Break big batch jobs into small chunks so they release locks very often. Updating a few hundred rows at a time lets normal user queries slip through. Check your slow queries to ensure every update and delete uses a sharp index. When queries touch rows in the exact same order, you also avoid lock conflicts.
Finally, add retry logic in your app code for ER_LOCK_WAIT_TIMEOUT events. The error message itself asks you to try restarting the failed transaction. Note that by default, a timeout only rolls back the single failed statement. Your app should explicitly roll back the whole transaction before it tries the work again. Keep human sessions safe by setting timeouts on idle manual connections as well.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
Does mysql error 1205 roll back the whole transaction?
By default, this error only stops the single statement that timed out. Your app must run an explicit rollback command to cancel the earlier statements safely.
How is mysql error 1205 different from a deadlock?
A deadlock happens when two sessions wait on each other in a closed loop. A lock wait timeout means one session simply waited too long for a busy lock.
Should I increase the lock wait timeout limit to fix this?
Increasing the timer usually hides the real bug and ties up app connections. Fix the slow blocking query or add a missing index instead of raising the timer.
Related guides
In this post