数据库
首页 > 数据库> > mysql – 非常慢的alter table(即使没有行)

mysql – 非常慢的alter table(即使没有行)

作者:互联网

我的Mysql设置有问题:我制作的每个alter table大约需要5分钟才能完成,即使表是完全空的.

有时查询甚至因超时而失败(错误2013:在查询SQL语句期间丢失了与MySQL服务器的连接:ALTER TABLE …).

此外,该表位于测试数据库中,因此不会同时进行其他查询.

我在12 CPU机器上使用Mysql 5.7,所以我不认为硬件是问题所在.

你知道如何解决这个问题吗?

谢谢你的时间

编辑:
运行show full processlist时

Altering table  ALTER TABLE ...
Waiting for table metadata lock ALTER TABLE ...

PS:此行为发生在任何表上,并与每个ALTER TABLE语句一起发生

编辑:
这个问题在Mysql 5.7.8中得到了解决

解决方法:

在这里尝试您的查询.

https://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html

如果在查询中有任何不好,你会发现它.

其他

完全转储和重新加载比alter更快.

- Create a new table (using the structure of the current table) with the new column(s) included.

- execute a INSERT INTO new_table SELECT (column1,..columnN) FROM current_table;

- rename the current table

- rename the new table using the name of the current table.

标签:mysql,sql,alter-table
来源: https://codeday.me/bug/20190711/1434359.html