Solved

merge/sync two mysql databases

Posted on 2012-03-21
4
282 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP & MySQL - Rounding Results from a Select Query 3 34
change database name 2 36
Combining Queries 7 27
SQL querys that gives me from one table into another. 2 23
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

792 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