简体   繁体   English

将数据从myisam复制到innodb

[英]Copying data over to innodb from myisam

I currently have a database based on a MYISAM storage engine that has a few thousand records. 我目前有一个基于MYISAM存储引擎的数据库,它有几千条记录。 I want to convert my database over to InnoDb storage engine. 我想将我的数据库转换为InnoDb存储引擎。

It won't be a simple ALTER storage engine command, since I need to add foreign keys to to the current database schema( the current MyISAM db schema does have primary keys though) before I convert it over to InnoDb. 它不会是一个简单的ALTER存储引擎命令,因为在将其转换为InnoDb之前,我需要将外键添加到当前数据库模式(当前MyISAM数据库模式确实有主键)。

My question is once I convert the DB over to InnoDb would restoring the data from the current MYISAM engine to InnoDb engine would be as simple as firing a PhpMyAdmin instance and back up the data (minus the db schema or structure) and then restore it to the Innodb engine? 我的问题是,一旦我将数据库转换为InnoDb,将数据从当前的MYISAM引擎恢复到InnoDb引擎就像启动PhpMyAdmin实例并备份数据(减去数据库模式或结构)一样简单,然后将其还原为Innodb引擎?

What are the potential hurdles in doing this? 这样做有什么潜在的障碍?

Is this the correct way to go about this or what are the various other easier or better ways to restore data? 这是解决此问题的正确方法,还是其他各种更简单或更好的方法来恢复数据?

It won't be a simple ALTER storage engine command, since i need to add foreign keys to to the current database schema 它不会是一个简单的ALTER存储引擎命令,因为我需要将外键添加到当前数据库模式

Why not? 为什么不? Sure backup the data first, that is always a good idea, but you don't need to dump and restore the data, you can issue your simple ALTER TABLE, such as: 首先确保备份数据,这总是一个好主意,但您不需要转储和恢复数据,您可以发出简单的ALTER TABLE,例如:

ALTER TABLE `tablename` ENGINE = InnoDB;

After that you can add any index and foreign key. 之后,您可以添加任何索引和外键。 If any new foreign key fails, you've to fix your data and try again. 如果任何新外键失败,您需要修复数据并重试。

When you add foreign keys first, you have to copy your data in a certain order, otherwise your data won't be added because of foreign key constraints. 首先添加外键时,必须按特定顺序复制数据,否则由于外键约束而不会添加数据。 Therefore, the best thing is checking (through SQL queries) if you can fulfill your foreign key constraints with your current dataset, then copy the data, afterwards, define foreign keys. 因此,最好的方法是检查(通过SQL查询)是否可以使用当前数据集实现外键约束,然后复制数据,然后定义外键。 But if you export your data from an InnoDB database with PHPMyAdmin, the order is already fulfilled and you can re-import it without any problems. 但是如果您使用PHPMyAdmin从InnoDB数据库导出数据,则订单已经完成,您可以毫无问题地重新导入它。

You could probably add the foreign keys later 您可以稍后添加外键

  1. Alter the table to use a new engine 改变表格以使用新引擎

  2. Alter each table to use foreign keys 更改每个表以使用外键

I only see one issue with that and that would be if the foreign keys are broken to start with. 我只看到一个问题,那就是如果外键被打破开始。

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

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