Reputation: 4303
I just had my site hacked and they were able to do some damage to my current database.
Anyway, I have a backup from few days ago. The problem is that the current database had a few thousand more posts and threads / users.
I am simply wondering how I could possibly go about merging the two databases?
The two databases have the exact structure, and I want the backup to overwrite any record from the current database, just that I want the current database to populate any new records like posts, threads, users and such.
I know you can merge two tables, if they have the exact structure, but what about two databases that have the same structure?
Upvotes: 1
Views: 11251
Reputation: 1
In my experience ON DUPLICATE KEY IGNORE did not work. Instead I found
INSERT IGNORE ta2_table SELECT * FROM ta1_table;
worked like a charm
Upvotes: 0
Reputation: 1563
there was some ways to do it: 1.) use Command line tools like schema Sync and mysql diff
2.) or Using SQLyog
find out more here http://blog.webyog.com/2012/10/16/so-how-do-you-sync-your-database-schema/
Upvotes: 0
Reputation: 26033
I assume you have a schema s1
and a schema s2
.
To insert all rows of a table in s1 into a table in s2, while overwriting existing lines, you can use:
REPLACE INTO s2.table_name
SELECT * FROM s1.table_name;
If you do not want to touch existing lines:
INSERT INTO s2.table_name
SELECT * FROM s1.table_name
ON DUPLICATE KEY IGNORE;
Upvotes: 3