MySql:由于 MyISAM 和 InnoDB 混合,完整性约束失败。如何安全地解决这个问题?
我有一个在 Django 和 MySql 上运行的网站。
部分数据库表使用 InnoDB 作为引擎,其他一些使用 MyISAM。
这没有什么特别的原因。该项目是很久以前开始的,我认为这是由配置更改引起的。
当 InnoDB FK 引用 MyISAM 表时,这会导致某些完整性约束失败。将表从 MyISAM 更改为 InnoDB 可以解决该问题。
我的问题是该网站正在制作中。它已经有了这种混合的桌子。有很多桌子。
有没有一种干净、安全的方法来解决这个问题?我是否必须将所有 MyISAM 表更改为 InnoDB?这样做有风险吗?
预先感谢您的帮助
I have a web site running on Django and MySql.
Part of the db tables are using InnoDB as engine and some other are using MyISAM.
There is no special reason for that. The project was started a long time ago and I think it is caused by a change in a configuration.
This cause some integrity constraint to fail when a InnoDB FK is referencing a MyISAM table. Changing the table from MyISAM to InnoDB fix the problem.
My problem is that this site is under production. It already has this mix of tables. There is a lot of tables.
Is there a clean and safe way to fix this problem? Do I have to change all MyISAM tables into InnoDB? Is there any risk to do that?
Thanks in advance for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当然可以使网站离线并将 MyIsam 表转换为 InnoDb。 (当然,请先备份数据库。)
不过,生产网站上的最大质量风险并不是更改表的存储引擎。当系统投入生产时,它开始强制实施数据库完整性约束。您可能会发现需要进行大量数据修复才能强制执行约束。
您可能最明智的做法是构建该系统(网站和数据库)的卷影副本并仔细完成所有更改。跟踪您在卷影副本上执行的命令和配置更改,以便在证明它们有效后可以在实时副本上再次执行这些操作。但它们也有可能行不通。
在这个虚拟机时代,卷影副本很容易实现。
You can certainly take the web site offline and convert your MyIsam tables to InnoDb. (Do back up the db first, of course.)
Your big quality risk on a production web site isn't changing a table's storage engine, though. It's starting to enforce database integrity constraints while the system is in production. You may find that you have a lot of data repair to do to allow the constraints to be enforced.
You are probably wisest to build a shadow copy of this system (web site and DB) and work through all your changes carefully. Keep track of the commands and configuration changes you do on the shadow copy, so you can do them again on the live copy when you've proven that they work. But there is some chance they won't work.
Shadow copies are easy in this age of virtual machines.