user481913
user481913

Reputation: 1018

Copying data over to innodb from myisam

I currently have a database based on a MYISAM storage engine that has a few thousand records. I want to convert my database over to InnoDb storage engine.

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.

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?

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?

Upvotes: 0

Views: 544

Answers (3)

Andreas Wederbrand
Andreas Wederbrand

Reputation: 40061

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.

Upvotes: 0

stivlo
stivlo

Reputation: 85546

It won't be a simple ALTER storage engine command, since i need to add foreign keys to to the current database schema

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 `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.

Upvotes: 3

belgther
belgther

Reputation: 2534

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. 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.

Upvotes: 0

Related Questions