MySQL 如果终止一个长时间运行的alter 查询会发生什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2731894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:55:31  来源:igfitidea点击:

What happens if you kill a long-running alter query?

mysqlkillalter

提问by B T

What happens if you kill a long-running alter query? Will the alter query simply revert? How long could that take (as a proportion of the time it has already been running)?

如果终止一个长时间运行的alter 查询会发生什么?更改查询会简单地恢复吗?这需要多长时间(作为它已经运行的时间的一部分)?

What if that query is being replicated onto another server? Will killing the process on the other server revert the original server's alter query?

如果该查询被复制到另一台服务器上怎么办?杀死另一台服务器上的进程会恢复原始服务器的更改查询吗?

We're running mysql

我们正在运行 mysql

采纳答案by davek

It depends what you're doing. If you're running an alter table...add indexcommand on an InnoDBtable (not so sure about MyISAM), then it will just run and run as it copies the whole darn table lock-stock-and-barrel first: if it's in the middle of "copy to temp table" then it's pretty much unstoppable.

这取决于你在做什么。如果您在表an alter table...add index上运行命令InnoDB(不太确定MyISAM),那么它只会运行并运行,因为它首先复制整个该死的表 lock-stock-and-barrel:如果它在“复制到临时表的中间” “那么它几乎是不可阻挡的。

See here:

看这里:

In most cases, ALTER TABLE works by making a temporary copy of the original table. The alteration is performed on the copy, and then the original table is deleted and the new one is renamed. While ALTER TABLE is executing, the original table is readable by other sessions. Updates and writes to the table are stalled until the new table is ready, and then are automatically redirected to the new table without any failed updates.

在大多数情况下,ALTER TABLE 通过制作原始表的临时副本来工作。对副本执行更改,然后删除原始表并重命名新表。在执行 ALTER TABLE 时,其他会话可以读取原始表。对表的更新和写入会暂停,直到新表准备就绪,然后会自动重定向到新表,而不会发生任何失败的更新。

回答by dland

What if that query is being replicated onto another server?

如果该查询被复制到另一台服务器上怎么办?

The ALTER will be executed on that server as well, with the associated impacts.

ALTER 也将在该服务器上执行,并产生相关影响。

Will killing the process on the other server revert the original server's alter query?

杀死另一台服务器上的进程会恢复原始服务器的更改查询吗?

Nope. The original server has no back channel to learn about what occurred (or didn't) on the slave. If you kill the ALTER on the slave, then you will wind up in the situation where the master has the new constraint or index, and the slave doesn't. This is rarely a recipe for happiness :)

不。原始服务器没有反向通道来了解从属服务器上发生(或未发生)的事情。如果您终止了从属设备上的 ALTER,那么您最终会遇到主设备具有新约束或索引而从属设备没有的情况。这很少是幸福的秘诀:)

Once an ALTER enters the replication log, you either have to let it run everywhere, or kill it everywhere.

一旦 ALTER 进入复制日志,你要么让它到处运行,要么到处杀死它。