小的alter table无限期挂起在MySQL上

时间:2015-11-12 21:52:14

标签: mysql

我试图运行ALTER TABLE在MySQL的200行表中添加一列。它在几个盒子上本地工作正常,但在生产中无限期挂起(让它运行长达5分钟)。

执行SHOW processlist;我可以看到它始终是Waiting for table metadata lock。进程列表显示它是最早运行的查询,所以我不知道它在等什么,或者为什么它等待它不会完成或被MySQL杀死。有什么想法吗?

SHOW ENGINE INNODB STATUS\G的交易部分如下:

------------
TRANSACTIONS
------------
Trx id counter 4148381
Purge done for trx's n:o < 4148307 undo n:o < 0 state: running but idle
History list length 699
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 4148291, not started
MySQL thread id 123643, OS thread handle 0x7f392b31d700, query id 467771426 some_ip root cleaning up
---TRANSACTION 4148286, not started
MySQL thread id 123642, OS thread handle 0x7f392b538700, query id 467771334 some_ip root cleaning up
---TRANSACTION 4148280, not started
MySQL thread id 123641, OS thread handle 0x7f39304ee700, query id 467771083 some_ip root cleaning up
---TRANSACTION 4148274, not started
MySQL thread id 123640, OS thread handle 0x7f392b569700, query id 467771047 some_ip root cleaning up
---TRANSACTION 4148268, not started
MySQL thread id 123639, OS thread handle 0x7f392b102700, query id 467770952 some_ip root cleaning up
---TRANSACTION 4148263, not started
MySQL thread id 123638, OS thread handle 0x7f39304bd700, query id 467770703 some_ip root cleaning up
---TRANSACTION 0, not started
MySQL thread id 123635, OS thread handle 0x7f392b507700, query id 467770298 some_ip root cleaning up
---TRANSACTION 4148245, not started
MySQL thread id 123634, OS thread handle 0x7f392b443700, query id 467770261 some_ip root cleaning up
---TRANSACTION 4148230, not started
MySQL thread id 123633, OS thread handle 0x7f392b753700, query id 467770267 some_ip root cleaning up
---TRANSACTION 4148303, not started
MySQL thread id 123632, OS thread handle 0x7f392b2ec700, query id 467771749 some_ip root Waiting for table metadata lock
ALTER TABLE some_table
---TRANSACTION 4148379, not started
MySQL thread id 123568, OS thread handle 0x7f393048c700, query id 467775687 some_ip root cleaning up
---TRANSACTION 4148380, not started
MySQL thread id 123563, OS thread handle 0x7f392b68f700, query id 467775899 some_ip root cleaning up
---TRANSACTION 4148373, not started
MySQL thread id 123562, OS thread handle 0x7f392b228700, query id 467774889 some_ip root cleaning up
---TRANSACTION 0, not started
MySQL thread id 123453, OS thread handle 0x7f392b474700, query id 467775900 some_ip root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 4148302, ACTIVE 143 sec
MySQL thread id 123645, OS thread handle 0x7f392b6c0700, query id 467771503 some_ip root cleaning up
Trx read view will not see trx with id >= 4148303, sees < 4148303

2 个答案:

答案 0 :(得分:1)

我们的制作中也有类似的问题。问题是另一个服务正在访问数据库,当尝试运行Alter Command时会进入无限循环。

在我们的案例中,

  1. 我们停止了应用服务器 - Weblogic
  2. Ran ALTER Command
  3. 重新启动数据库实例
  4. 重新启动了Weblogic实例。

答案 1 :(得分:-1)

在ALTER之前尝试“FLUSH TABLES”