MYSQL 锁等待 Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

今天布署应用的时候突然报下面的错、总结一下以免下次再次碰到。

MYSQL 锁等待 Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

在5.5中,information_schema库中增加了三个关于锁的表(MEMORY引擎);

innodb_trx ## 当前运行的所有事务

innodb_locks ## 当前出现的锁

innodb_lock_waits ## 锁等待的对应关系

解决方案

      1.进入mysql服务端中的information_schema数据库

      2.执行select * from information_schema.INNODB_TRX;

      3.找到这个字段trx_mysql_thread_id,把这一列的线程ID全部杀掉(下面这张图是正常的,没有锁等待,发现trx_state: WAIT表示锁等待,就会出现上图的报错)MYSQL 锁等待 Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

       4.执行 kill trx_mysql_thread_id;比如 kill 207456