Forums

ERROR 1205 (HY000): Lock wait timeout exceeded

Hello,

Today, recently, I created a database called mybusinessdb, but, I am not successful, as I had in my local development environment.

It is the following when using the list of all companies, I have a CRUD, I can register branches related to company X, the operation is correct, until now. The problem is that if I want to remove this company X, my page is not successfully redirected. Send me this warning on the blank page:

500 Internal Server Error <br> The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

So, I did a test, I entered my database console, I did this command:

mysql> DELETE FROM company WHERE id = 1;

It took a long time to answer, and the answer was mentioned in the title:

ERROR 1205 (HY000): Lock wait timeout exceeded

Guys, what should I do?

I don't understand SQL very much, it's my first time using an app on a cloud hosting server, I was thinking of a way to restart my database via console using this command:

service mysql restart

Also, I was unsuccessful.

Can you help me?

How does your code doing that deletion looks like? There must be some other operation happening at the same time in that table, that prevents your deletion to acquire a lock.

Hi fjl,

I have two functions that I use to remove.

The first is to remove a company from the empresa(EN -> company) table.

Follow the image of my Pycharm IDE, in the web application file (config.py), the comments in Python are in my official Portuguese language, but, I believe it will not be a problem:

https://ibb.co/NnvvYtS

In the second function, to remove a registered branch from the unidade (EN -> branch) table

Let's see in the image, the second function:

https://ibb.co/ZM8N2J3

If you're getting a "Lock wait timeout" error, that suggests that there is some other process/query that is holding a lock on the table that is preventing the deletion from happening. Locks will generally be held by processes that are opening transactions and then taking a long time to close them. In your code, any exception after opening the transaction but before the commit would cause the table to be locked and so any following attempts to update the table would fail with a lock wait timeout.

Make sure that you are rolling your transactions back in an except blocks so that they get rolled back if there is an exception. It would also be a good idea to place the closing of the cursor and the connection into a finally block.