This post was updated 685 days ago and some of the ideas may be out of date.

今天删除数据的时候突然提示:#1205 - Lock wait timeout exceeded; try restarting transaction

Mysql数据库采用InnoDB模式,默认参数:innodb_lock_wait_timeout设置锁等待的时间是50s,一旦数据库锁超过这个时间就会报错。

解决办法记录如下:

第一步:

mysql> select trx_mysql_thread_id from information_schema.innodb_trx;
+---------------------+
| trx_mysql_thread_id |
+---------------------+
|              980767 |
+---------------------+
1 row in set (0.00 sec)

第二步:找到执行异常的事务线程id

然后直接执行:

mysql> kill 980767;

Query OK, 0 rows affected (0.00 sec)

再次执行SQL一切正常!!

参考资料

https://zhuanlan.zhihu.com/p/253128029