Merge MySQL Database Tables

vicnumb Mar 3, 2013

Mar 03 2013 Published by under PHP & MySQL

In a script I administrate mystically disappeared part of data. Since php script is zend encrypted it is difficult to find out why data were lost, but anther problem is restoring data.

Looking through backups I found a 10 days old backup with all data in place.

All I had to do is to follow the steps:
1. Make a copy of damaged database
2. Replace it with backup database
3. Unite tables of 2 databases to add into restored database the last 10 days missing records.

All appeared pretty simple to do, just repeat the same command as many times as many tables you have.

INSERT IGNORE
  INTO original_database.table_name
SELECT *
  FROM damaged_database_copy.table_name

All this job took me only 20 minutes, uniting database tables this way saved a lot of time.

No responses yet

Leave a Reply