简体   繁体   中英

ERROR 1205 (HY000): Lock wait timeout exceeded on update mysql

I am running following update -

update table_x set name= 'xyz' where id = 121;

and getting - ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

I googled it number of times and adding extra time to innodb_lock_wait_timeout not helping me out.

Please let me know the root cause of this issue and how I can solve it. I am using mysql 5.6(master-master replication) on dedicated server. Also table_x(Innodb table) heavily used in database. Autocommit is on.

Looks like there is some lock on any of your other transaction. You can check the status of INNODB by using this:

SHOW ENGINE INNODB STATUS\G 

Check if there is any lock on the tables like this:

show open tables where in_use>0;

And then kill that processes which are locked.

Find out what other statement is running at the same time as this UPDATE . It sounds as if it is running a long time and hanging onto the rows that this UPDATE needs. Meanwhile this statement is waiting.

One way to see it is to do SHOW FULL PROCESSLIST; while the UPDATE is hung.

(In my opinion, the default of 50 seconds for innodb_lock_wait_timeout is much to high. Raising the value only aggravates the situation.)

If you give up on fixing the 'root cause' of the conflict, then you might tackle the issue a different way.

  1. Lower innodb_lock_wait_timeout to, say, 5.
  2. Programmatically catch the error when it times out and restart the UPDATE .
  3. Do likewise for all other transactions. Other queries may also be piling up; restarting some may "uncork" the problem.

SHOW VARIABLES LIKE 'tx_isolation'; -- There may be a better setting for it, especially if a long-running SELECT is the villain.

I have solved the problem. I tried different values for innodb_lock_wait_timeout , also tried to change queries but got the same error. I did some research and asked my colleagues about hibernate.

They were doing numbers of transaction which include updating main table and committing in the end. So, I suggested them to use commit on each transaction. Finally I am not getting any lock wait time out errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM