LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-18-2014, 10:54 AM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
Best way to compare MySQL database between 2 servers


We just online cloned a MySQL server to a virtual machine, but what is the best way to compare the database on the real physical server to the clone we just made, to make sure they match (that nothing got messed up during the cloning)?
 
Old 09-18-2014, 01:03 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
I can't presume to tell you the best way, but since the mysqldump command produces a text output file, two dump files can simply be diffed.
 
1 members found this post helpful.
Old 09-18-2014, 01:04 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Well,
Code:
mysqldump -uroot -p <db> > /path/to/file.sql
I trust and at the other end
Code:
mysql -uroot -p <db> < /path/to/file.sql
How was it cloned exactly?
 
1 members found this post helpful.
Old 09-18-2014, 01:21 PM   #4
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
It was hot/online cloned to VMware, and I think mysqld was still running when they did it, so i'm kinda leery on if it actually worked right getting the db's, as we've never cloned anything before.
 
Old 09-18-2014, 02:45 PM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
OK, for one of the databases, i dumped them from each server, and diff'd them, here was the output

Quote:
365c365
< -- Dump completed on 2014-09-18 14:54:05
---
> -- Dump completed on 2014-09-18 15:20:17
So i think that means they are identical since the line numbers are the same in line 1 and lines 2 and 4 are just timestamps from the dumps, correct?

I have another one where it appears to have found a bunch of differences though based on how many times i had to scroll.
 
Old 09-18-2014, 04:20 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Erm, I hate diff results, gives me a migraine.

Another method is to try mysqlhotcopy...
or creating the same dbs on the new host and stopping the source mysql server daemon and rsync the /var/lib/mysql/DIRs over to the new host...
or set the new host as a slave mysql-server...
or...
mysql> use <db>; show table status;

I've always used mysqldump and just let the interface(s) and the users (gasp) tell me what's what.
Easiest method is the one I tend to use/utilize.
Do 2 mysql dumps (back-to-back) and diff those results.
If they're the "same" then do an import.
Code:
# mysqldump mysql > file.sql
# mysqldump mysql > file.sql2
diff file.sql file.sql2
543c543
< -- Dump completed on 2014-09-18 14:18:46
---
> -- Dump completed on 2014-09-18 14:18:54
but these seem comparable to what you have already done.

Last edited by Habitual; 09-19-2014 at 08:29 AM. Reason: s/Eesiest/Easiest
 
Old 09-18-2014, 04:32 PM   #7
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
everything lately gives me a migraine, I feel your pain haha

Maybe i'll just try restoring the ones that show multiple changes from diff and pray that doesn't blow anything up. luckily the largest/most important database was the one I posted the results from earlier, so my stress level went from 10 to about a 6
 
Old 09-23-2014, 12:45 PM   #8
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
May have lucked out on this one, only 1 of the 8 db's had any differences other than the backup timestamp
 
Old 09-23-2014, 12:49 PM   #9
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Rep: Reputation: 22
I've had problems with mysqldump not exporting or importing properly. I've always just rsync'd the /var/lib/mysql/<database> directory to the new server. It's fine as long as you aren't changing distros.
 
1 members found this post helpful.
Old 09-23-2014, 12:51 PM   #10
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
It's a straight clone. The db in question is for a mediawiki site. do you think that one is safe to just rsync the directory for? I don't know much about mediawiki.
 
Old 09-23-2014, 01:26 PM   #11
deathsfriend99
Member
 
Registered: Nov 2007
Distribution: CentOS 6
Posts: 200

Rep: Reputation: 22
I've never had a problem with using rsync for databases.
Just make sure you keep the same attributes and do an update. I'm assuming since you used vmware to clone, they have the same passwd, group, and shadow files, so doing a simple:

Code:
(I'm assuming the name of the database is mediawiki)
# rsync -avrlu /var/lib/mysql/mediawiki root@yournewmachine:/var/lib/mysql/mediawiki
Should do the trick.

Would be beneficial to stop mysqld services on both machines before the transfer.
Also, double check the ownership is correct on the destination before firing up the mysqld server

My setup is CentOS, so I'm not sure where other distros keep their mysql databases.
user:group for me is mysql:mysql

Last edited by deathsfriend99; 09-23-2014 at 01:28 PM.
 
1 members found this post helpful.
Old 09-23-2014, 01:30 PM   #12
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
cool, thanks. looking at the physical and clone mediawiki sites, I can't actually find a difference in the site. I wonder if the changes in the db were actually just from people reading its pages, so maybe I don't even need to do this.

Wish there was some tool that I could say, look at this site and all the stuff it links to, and compare it to this site and all the stuff it links to, and tell me what the differences are. cuz really if nothing is different for the users, then i'm good with it, know what I mean.
 
Old 09-23-2014, 07:02 PM   #13
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
mysqldump was designed to dump a live, active database.
If you import the dumped file in the remote mysql server you have a guaranteed non-corrupt database.

When you do a diff of two dumps and it shows no differences you can be sure the databases are identical. However if you do encounter differences it doesn't mean something went wrong. Since you dumped a live database changes might have been added during or after the dump process.

rsyncing a live mysql directory is a bad idea. It might go well in 99% of the cases, but there is still a chance you end up with a corrupted database. It is simply the wrong way to do it.

I have never seen rsync itself making an error during copy.

jlinkels
 
Old 09-24-2014, 08:12 AM   #14
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
What I ended up doing, even though it sounds so silly, was to just look at the mediawiki site page by page, as displayed from both servers, and I actually couldn't find any visible differences on any of the pages. So not sure what the diffs were between the 2 db dumps I did, or what they signified, even though I could have missed it with my eyeball test.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to compare 2 tables data from different linux servers with mysql using perl script tarun28jain Programming 3 10-16-2012 06:54 AM
LXer: Multiserver Setup With Dedicated Web, Email, DNS & MySQL Database Servers On Debian Squeeze Wi LXer Syndicated Linux News 0 10-09-2011 10:00 PM
Compare two directories in different servers freakysk Linux - General 3 03-29-2011 09:28 AM
LXer: Installing A Multiserver Setup With Dedicated Web, Email, DNS And MySQL Database Servers On De LXer Syndicated Linux News 0 08-19-2010 07:30 PM
Compare files in two different servers elainelaw Linux - Software 2 07-16-2009 07:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration