Getting “Lock wait timeout exceeded; try restartin

2019-01-01 07:48发布

I'm running the following MySQL UPDATE statement:

mysql> update customer set account_import_id = 1;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

I'm not using a transaction, so why would I be getting this error? I even tried restarting my MySQL server and it didn't help.

The table has 406,733 rows.

14条回答
闭嘴吧你
2楼-- · 2019-01-01 08:40

None of the suggested solutions worked for me but this did.

Something is blocking the execution of the query. Most likely another query updating, inserting or deleting from one of the tables in your query. You have to find out what that is:

SHOW PROCESSLIST;

Once you locate the blocking process, find it's id and run :

KILL {id};

Re-run your initial query.

查看更多
浪荡孟婆
3楼-- · 2019-01-01 08:42

In my instance, I was running an abnormal query to fix data. If you lock the tables in your query, then you won't have to deal with the Lock timeout:

LOCK TABLES `customer` WRITE;
update customer set account_import_id = 1;
UNLOCK TABLES;

This is probably not a good idea for normal use.

For more info see: MySQL 8.0 Reference Manual

查看更多
登录 后发表回答