WMI
WMI

Reputation: 159

MySQL, Auto Increment, Export and Import

I'm trying to import a SQL file into MySQL that has auto increment values. I know that if I replace those numbers with null, or skip that column all together, it will generate new values when importing. However, I'm trying to keep the old values. Is this possible? The reason being is that all those numbers are used in other tables for easy referencing between them.

If you need a reference to what I'm talking about, look at wp_users and wp_usermeta in Wordpress. The ID in wp_users is used in wp_usermeta as the user_ID. If I were to import, for example, wp_users and have it generate new ID's, then they would not match the wp_usermeta user_ID.

I looked in previous questions which are similar to this one and there was only one question asked that was close. However, it's slightly different than this question and the answers did not help.

If it is not possible to import and retain old increment values, would my best option be to create my own script (php) to import, generate new increment values, and update the other tables while importing?

Upvotes: 3

Views: 4025

Answers (1)

Alex
Alex

Reputation: 1205

It should be perfectly possible, just go to your MySQL database and try it out? It usually stores the auto increment value when you export the data from the database.

You could test this out by inserting a new record into the database once you have imported it in? To test that the auto increment value is working as expected.

Upvotes: 1

Related Questions