1

I have three relational tables with data in MYSQL db1, and the same schemas with data in MYSQL db2, I need to combine the data into MYSQL db2. what's the right way to do it?
should I dump the db1 tables individually (with the option of adding a high number to the ids so that the data don't conflict)?

1 Answer 1

1

You can simply append the data by doing something like this:

INSERT INTO `db2`.`table` SELECT NULL, `col2`, `col3` FROM `db1`.`table`

This assumes that the schema is so that the first column is the auto incrementing ID. By selecting NULL for that, new keys will be generated, all other columns should be selected separately and will form the rest of these new records.

If you order the select from the above statement by the ID and they are contiguous, you can simply add the first inserted ID value to the foreign keys for other tables.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .