Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Error Code: 1205. Lock wait timeout during update with inner join

I am trying to update the Time_Stamp field in my table, simple_pack_data, to match the values in the similarly titled field in my temp_data table. The tables each have fields called Test_Number and Time_Marker, which I'm using to INNER JOIN the tables. Time_Marker is like a reading count, where Time_Stamp is an actual time from the start of the test.

I want to update the Time_Stamp one test at a time, so the code I have been trying is:

UPDATE simple_pack_data s
INNER JOIN (
    SELECT *
    FROM temp_data t
    WHERE t.Test = "3"
    ) AS tmp
ON s.Test_Number = tmp.Test_Number AND s.Time_Marker = tmp.Time_Marker
SET s.Time_Stamp = tmp.Time_Stamp
WHERE s.Test_Number = "3";

When I run this it takes over 50 seconds and I get the 1205 error. If I run a similarly structured select statement:

SELECT *
FROM simple_pack_data s
INNER JOIN (
    SELECT *
    FROM temp_data t
    WHERE t.Test = "3"
    ) AS tmp
ON s.Test_Number = tmp.Test AND s.Time_Marker = tmp.Time_Marker
WHERE s.Test_Number = "3";

It takes much less than a second and I know join is working fine. Is the update really taking that long? If so, is there any way to change the timeout value so it can get through it?

like image 345
eh_whatever Avatar asked Oct 18 '13 20:10

eh_whatever


People also ask

How can remove wait timeout lock in MySQL?

Dealing With a InnoDB Lock Wait Timeout When deploying a MySQL-based cluster, ClusterControl will always set innodb_rollback_on_timeout=1 on every node. Without this option, your application has to retry the failed statement, or perform ROLLBACK explicitly to maintain the transaction atomicity.

How do I unlock a locked table in MySQL?

You can implicitly release the table locks. If the connection to the server terminates explicitly or implicitly all the locks will be released. You can release the locks of a table explicitly using the UNLOCK TABLES statement.

What Causes lock wait timeout exceeded?

The “Lock wait timeout exceeded; try restarting transaction” error will occur when a query cannot proceed because it is blocked by a rowlock. Typically, a deadlock happens when two or more transactions are writing to the same rows, but in a different order.


2 Answers

This error is entirely MySQL not doing as it should. The best solution is to get off of MySQL, but lacking that ability, this performance blog post has helped me get around this in the past.

MySQL has a lot of these little gotchas. It's like working in Access, half the time the program is going to do the wrong thing and not raise an error.

like image 127
Twelfth Avatar answered Oct 07 '22 14:10

Twelfth


Try see if your MySQL Server had a process in running.

To see that, run the command on MySQL Client:

SHOW FULL PROCESSLIST;

See id, state and info columns and analyze the problem. After you find the problem, kill the process with:

KILL <PROCESS ID>;
like image 31
Wendel Avatar answered Oct 07 '22 15:10

Wendel