Solved

merge/sync two mysql databases

Posted on 2012-03-21
4
276 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now