問題
今天變更數據表時,一直操作失敗,通過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