Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

innodb_lock_wait_timeout increase timeout

I am using MySQL database and trying to update records just after insert so I am getting following error ER_LOCK_WAIT_TIMEOUT: Lock wait timeout exceeded; try restarting transaction. So I decrease timeout by following query:-

set GLOBAL innodb_lock_wait_timeout=1

So my question is:- is it ok to do that? Will it lead to other problems like performance issue etc.?

Thank You for your help.

like image 933
user3819192 Avatar asked Feb 26 '15 05:02

user3819192


People also ask

How do I fix mysql lock wait timeout exceeded?

In summary, if we face a “Lock Wait Timeout Exceeded” error in MySQL, we need to first understand the effects that such an error can have to our infrastructure, then track the offensive transaction and act on it either with shell scripts like track_lockwait.sh, or database management software like ClusterControl.

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.

What is mysql lock wait timeout?

A lock wait timeout causes InnoDB to roll back the current statement (the statement that was waiting for the lock and encountered the timeout). To have the entire transaction roll back, start the server with --innodb-rollback-on-timeout enabled.


1 Answers

If this is a web application and you are trying to hang onto the transaction from one page to the next, don't; it won't work.

What do you mean by "just after"? If you are doing nothing between the two statements, even a timeout of 1 second should be big enough.

mysql> SET GLOBAL innodb_lock_wait_timeout = 1;
mysql> SELECT @@innodb_lock_wait_timeout;
+----------------------------+
| @@innodb_lock_wait_timeout |
+----------------------------+
|                         50 |
+----------------------------+
mysql> SET SESSION innodb_lock_wait_timeout = 1;
mysql> SELECT @@innodb_lock_wait_timeout;
+----------------------------+
| @@innodb_lock_wait_timeout |
+----------------------------+
|                          1 |
+----------------------------+

To explain GLOBAL vs SESSION for VARIABLES: The GLOBAL value is used to initialize the SESSION value when your connection starts. After that, you can change the SESSION value to affect what you are doing. And changing the GLOBAL value has no effect on your current connection.

Changing the timeout to 1 is quite safe (once you understand GLOBAL vs SESSION). The only thing that will change is the frequency of getting that error.

like image 184
Rick James Avatar answered Oct 03 '22 19:10

Rick James