Software⏱️ 4 min read📅 2026-06-03

How to Fix: Getting "Lock wait timeout exceeded; try restarting transaction" even though I'm not using a transaction

MySQL Lock wait timeout exceeded error when not using transactions.

Quick Answer: Check for table locks, use EXPLAIN to identify potential bottlenecks and optimize queries.

The 'Lock wait timeout exceeded; try restarting transaction' error is a common issue that affects MySQL users who are not using transactions. This error occurs when there is a contention between two or more processes trying to access the same data in the database. It can be frustrating for developers and administrators, especially when they are unable to identify the source of the contention.

In this guide, we will walk you through the root causes of this error and provide two primary fix methods to resolve it. We will also discuss alternative solutions and offer helpful tips for avoiding similar issues in the future.

💡 Why You Are Getting This Error

  • The primary reason for this error is a lack of isolation between database sessions. When multiple sessions are accessing the same table simultaneously, they may interfere with each other's operations, leading to contention and eventually the 'Lock wait timeout exceeded' error. This can occur due to various factors such as poorly designed queries, insufficient indexing, or inadequate locking mechanisms.
  • Another alternative reason for this error is a high volume of concurrent connections to the database server. If too many sessions are competing for access to shared resources, it can cause contention and lead to the lock wait timeout exceeded error.

🛠️ Step-by-Step Verified Fixes

Optimizing Queries and Indexing

  1. Step 1: Step 1: Analyze your queries to ensure they are optimized for performance. Check that you are using efficient join methods, indexing the columns used in WHERE and JOIN clauses, and avoiding unnecessary subqueries.
  2. Step 2: Step 2: Implement locking mechanisms to prevent contention between sessions. You can use ROW Locks or Table Locks to achieve this. For example, you can modify your UPDATE statement to include a LOCK TABLE clause: `UPDATE customer SET account_import_id = 1 LOCK TABLES customer WRITE`.
  3. Step 3: Step 3: Monitor your database performance and adjust your queries accordingly. Regularly monitor your query logs and adjust your indexing strategy as needed.

Increasing Server Resources

  1. Step 1: Step 1: Increase the number of available connections to your database server. This can be done by adjusting the `max_connections` setting in your MySQL configuration file or by increasing the value of the `connection_limit` parameter.
  2. Step 2: Step 2: Upgrade your server hardware to improve its performance. Adding more RAM, CPU cores, or storage capacity can help reduce contention and improve overall system performance.

✨ Wrapping Up

In conclusion, the 'Lock wait timeout exceeded; try restarting transaction' error is a common issue that can be resolved by optimizing queries and indexing, as well as increasing server resources. By following these steps and implementing effective locking mechanisms, you can minimize contention between database sessions and improve overall system performance.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions