简体   繁体   English

表锁定如何影响表引擎从MyISAM更改为InnoDB?

[英]How does table locking affect table engine change from MyISAM to InnoDB?

So I have been asked to change the engine of a few tables in a production database from MyISAM to InnoDB. 所以我被要求将生产数据库中的几个表的引擎从MyISAM更改为InnoDB。 I am trying to figure out how that will affect usage in production (as the server can afford no downtime). 我试图弄清楚这将如何影响生产中的使用(因为服务器无法承受停机时间)。

I have read some conflicting information. 我读过一些相互矛盾的信息。 Some information I have read state that the tables are locked and will not receive updates until after the conversion completes (IE, updates are not queued, just discarded until it completes). 我读过的一些信息表明表已锁定,并且在转换完成之后才会收到更新(IE,更新未排队,只是在完成之前被丢弃)。

In other places, I have read that while the table is locked, the inserts and updates will be queued until the operation is complete, and THEN the write actions are performed. 在其他地方,我已经读过,当表被锁定时,插入和更新将排队,直到操作完成,然后执行写操作。

So what exactly is the story here? 那故事到底是什么?

This is directly from the manual : 这直接来自手册

In most cases, ALTER TABLE makes a temporary copy of the original table. 在大多数情况下,ALTER TABLE会生成原始表的临时副本。 MySQL waits for other operations that are modifying the table, then proceeds. MySQL等待修改表的其他操作,然后继续。 It incorporates the alteration into the copy, deletes the original table, and renames the new one. 它将更改合并到副本中,删除原始表,并重命名新表。 While ALTER TABLE is executing, the original table is readable by other sessions. 在执行ALTER TABLE时,原始表可由其他会话读取。 Updates and writes to the table that begin after the ALTER TABLE operation begins are stalled until the new table is ready, then are automatically redirected to the new table without any failed updates. 对ALTER TABLE操作开始后开始的表的更新和写入将停止,直到新表准备就绪,然后自动重定向到新表而不会有任何失败的更新。

So, number two wins. 所以,第二名获胜。 They're not "failed", they're "stalled". 他们没有“失败”,他们“陷入僵局”。

The latter is correct. 后者是正确的。 All queries against a table that's being altered are blocked until the alter completes, and are processed once the alter finishes. 针对正在更改的表的所有查询都将被阻止,直到alter完成,并在alter完成后进行处理。 Note that this includes read queries (SELECT) as well as write queries (INSERT, UPDATE, DELETE). 请注意,这包括读取查询(SELECT)以及写入查询(INSERT,UPDATE,DELETE)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM