问题
今天变更数据表时,一直操作失败,通过show processlist查看一直显示Waiting for table metadata lock,及时kill改线程依然无法执行表变更。
定位
通过语句查看innodb的状态:
show engine innodb status \G;
------------
TRANSACTIONS
------------
Trx id counter 419465425
Purge done for trx's n:o < 419465425 undo n:o < 0 state: running but idle
History list length 2822
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 419465396, not started
MySQL thread id 12016531, OS thread handle 0x7f7d1a5a9700, query id 144951733 10.4.233.205 root cleaning up
---TRANSACTION 419465286, not started
MySQL thread id 12016230, OS thread handle 0x7f7d1a770700, query id 144951178 10.4.233.205 root cleaning up
.
.
---TRANSACTION 419412374, ACTIVE 3332 sec
1 lock struct(s), heap size 376, 0 row lock(s), undo log entries 1
MySQL thread id 11958847, OS thread handle 0x7f7d1acc5700, query id 144425269 10.4.238.126 root cleaning up
可以在TRANSACTIONS块看到有一个事务一直在执行,导致其他提交无法执行。
解决
杀掉长事务线程
kill 144425269