MySQL – How to Restore Old Backup Over New Data

MySQLrestore

We have a MySQL backup. Did some changes on our database and some data was lost. In the mean time new records were added.

We have to restore the mysql backup over our latest data.
Some of the tables have auto increment columns which means that we will end up with the same primary key but different values in some tables. The majority of the tables are from a many-to-many or one-to-many relationships.

What is the best approach to resync the same schema between the backup and the current data?

Best Answer

  1. Load your data in another database.
  2. Run LEFT JOINs one way, then the other way, to see what was deleted/new.
  3. Run a JOIN to see if the rows that exist in both are the same; fix if necessary.
  4. Run a multi-table DELETE to get rid of the the appropriate rows.
  5. Run INSERT...SELECT..LEFT JOIN to copy the missing rows in