MySQL Alter Table DB Freezes

时间:2019-03-19 14:51:53

标签: mysql linux database ubuntu-16.04 alter

I'm using Ubuntu 16.04.3 and mysql Ver 14.14 Distrib 5.7.22.

When I try to alter my db table column with the following command the database appears to freeze;

mysql> alter table records modify column name varchar(150);

Table size is 2.8MiB (6,000 records).

I'm simply trying to change the varchar(150) part.

I have tried to do the same thing in GUI programs such as HeidiSQL and Workbench, same result - program crashes and I have to restart the session.

I am logged into the db and server as root. I checked the /var/log/mysql/error.log but it only displays failed login attempts, nothing relevant to this error.

Any ideas what's going on or how I can troubleshoot this?

1 个答案:

答案 0 :(得分:0)

您是否有任何应用针对此表运行长时间运行的事务?如果有任何事务持有元数据锁,它将无法启动ALTER TABLE。

如果在ALTER TABLE挂起时可以在另一个窗口中运行SHOW PROCESSLIST,则它可能显示“等待元数据锁定”。

+----+------+-----------+------+---------+------+---------------------------------+------------------------+-----------+---------------+
| Id | User | Host      | db   | Command | Time | State                           | Info                   | Rows_sent | Rows_examined |
+----+------+-----------+------+---------+------+---------------------------------+------------------------+-----------+---------------+
|  4 | root | localhost | test | Query   |    0 | init                            | show processlist       |         0 |             0 |
|  5 | root | localhost | test | Query   |   15 | Waiting for table metadata lock | alter table foo...     |         0 |             0 |
+----+------+-----------+------+---------+------+---------------------------------+------------------------+-----------+---------------+

然后,您需要确定哪个应用程序具有阻止ALTER TABLE的打开的事务,并让该应用程序完成其事务,否则终止该事务。