Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

merge/sync two mysql databases

Posted on 2012-03-21
4
Medium Priority
?
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 24

Assisted Solution

by:johanntagle
johanntagle earned 1500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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