Solved

merge/sync two mysql databases

Posted on 2012-03-21
4
283 Views
Last Modified: 2012-03-26
I have two mysql databases with the same structure and a ton of tables.

I would like to merge the two.

(What happened was, I had to move to another hosting provider, and in the process, somebody placed an order on the old server, and my new database does not have this info. But the new database has new info, so I can't just replace it with the old one. I tried INSERT from TO, with individual tables, but there are too many linked tables, and I can't be sure everything was moved correctly.)

Maybe is there a widget out there that will sync these for me?
0
Comment
Question by:Kyle Hamilton
  • 2
  • 2
4 Comments
 
LVL 24

Assisted Solution

by:johanntagle
johanntagle earned 500 total points
ID: 37750107
Unfortunately I don't think there's a tool that can automatically fix this for you.  The problem is too specific to how the database is architected for a generally-available widget to address.  Also, if your app makes use of auto_increment integer primary keys, then you will likely have different records on the two databases that have the same keys.  I think you have two options:

If you have access to mysql binary logs on the old server, you can replay them from the time of transfer to see what DML SQLs were run, and you can run them on the new server.  Again, take note if there are auto-generated keys which you will need to assign new values to.

Other option is to import the old database to a different schema on the new server, then you do left outer joins on each table to determine what's on the old that isn't in the new.  You can make your SQL genrate the insert statement needed by using the concat function i.e. select concat('insert into tablename (col1, col2) values (', col1, ',', col2, ')') from .....
0
 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 0 total points
ID: 37750284
Thanks,

I ended up doing a little of two things:

INSERT IGNORE INTO `username_database`.`table` 
SELECT * 
FROM `username_databaseOld`.`table`

Open in new window


and a bunch of manual tweaking of id's and such...

What a pain the b*****

:)
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 37750298
Yup that's why for me it's better to just take a short downtime than to have to deal with such things. =)
0
 
LVL 25

Author Closing Comment

by:Kyle Hamilton
ID: 37764988
I'm accepting my solution not because it's a good one, but because it's what I did in the end to fix my issue. Thanks for your help.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question