User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 374,021 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,765 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 4148 | Replies: 6
Reply
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,873
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 109
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Moving database to new server

  #1  
Mar 9th, 2006
I would like to move my forum database to a new server. However, the MySQL database is approximately 700 megs, and takes a great deal of time to import. Doing a mysql> source backup.sql took well over 12 hours the last time I did it, and that was months ago. It will most likely take much longer than that.

What is the best way to go about doing this? My current plans would be to lock all new registrations and posting on the site for about two days while I copied over the database on the other machine. Then, set up the site to use the new database. I would be making the site read-only so that new data isn't being added to the old database which will be lost as soon as I set up the forum to use the new database. However, there has to be a more seamless way of doing it than making the site read only for two days.

If I were to leave the forum active, I would end up at the end of the day with two databases, one of them two days fresher than the other. Is there a way that I could then just import those two days worth of data to the new database? It's probably too good to be true, but is there some sort of database comparison utility that would work in this case?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Moving database to new server

  #2  
Mar 10th, 2006
Dani,

My customer's MySql db's are tiny--nothing like your 1GB monster. I simply use the mysqldump command. As you most surely know, this command simply creates a text file that includes all the SQL statements to create your tables and indexes and insert all the data. For you, these files would be enormous. You would want to dump one table at a time. You'll probably want to use the --opt option which locks tables and disables buffering. (Otherwise, mysqldump tries to buffer the entire table to memory before writing to file--bad idea with your big tables.)

You can use the mysqlimport program to import the mysqldump files.

I've not used mysqlhotcopy, but it's supposed to be faster than mysqldump. It is only for MyISAM and ISAM tables--which you probably have. That's the default table type, and all my tables in my MySQL databases are MyISAM. I guess 5.0 supports the InnoDB type. With InnoDB databases, you can simply copy the raw files from one server to another (as long as both computers use the same floating point logic, etc.)

Hmmm...reading more about mysqlhotcopy....this may be a good solution for you. (At your linux server prompt, read the doc using `perldoc mysqlhotcopy`--worked for me anyway.) From the manpage:
DESCRIPTION
mysqlhotcopy is designed to make stable copies of live MySQL databases.

Here "live" means that the database server is running and the database may be in active use. And "stable" means that the copy will
not have any corruptions that could occur if the table files were simply copied without first being locked and flushed from within the server.
mysqlhotcopy supports scp copying--meaning you could copy directly to the new server, but this would keep the live server locked longer. Assuming you have enough disk space, the docs recommend copying to local disk, then scp to the new server "at your leisure". Then again, you really want the db locked until the new system is online. Like you said, you don't ever want any more updates to the old db once you start the copy process.

I just haven't had experience with any relatively large MySql databases. Please follow up and let us know your experience.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,873
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 109
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Moving database to new server

  #3  
Mar 10th, 2006
Thanks for the reply, Troy. I actually use mysqldump nightly to do a large .sql dump of DaniWeb for backup reasons. Backing up to a massive .sql file is not a problem - it's not like I have to ever open the file in a text editor or something

The source statement that I referred to actually takes what is in the .sql file and imports it back into the database. THAT is what takes so long, because it has to do one INSERT query at a time. As you can imagine, there are hundreds of thousands of INSERT queries. Doing one INSERT query at a time takes much longer than simply writing line after line to a single text file.

I'm using MySQL 4 and am not sure yet whether to go 4 or 5 with the new database. I will have to research I assume. However, I will look into your suggestions. Thanks!
Reply With Quote  
Join Date: Jun 2007
Posts: 2
Reputation: webie is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
webie webie is offline Offline
Newbie Poster

Re: Moving database to new server

  #4  
Jun 22nd, 2007
HI cscgal ,

why not use the rsync program over ssh to move your database to new server I presume this would be on linux server.

the only think is you would need to shutdown both mysql servers to use rsync as you would get database errors.

commands are very simple:
login as root with putty secure shell to server.

1. shutdown mysql databases
run command service mysql stop on both servers.

2. run rsync to move database

login to new mysql server as root and type command:

rsync -av -e 'ssh -p 22' root@old-servers-ip-address:/var/lib/mysql/yourdatabase/ /var/lib/mysql/yourdatabase/

when completed restart mysql on both servers with service mysql start

your databse should now be on the new mysql server ready for use.
Last edited by webie : Jun 22nd, 2007 at 10:39 am.
Reply With Quote  
Join Date: Jul 2006
Location: Remunj
Posts: 142
Reputation: pritaeas is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 16
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Junior Poster

Re: Moving database to new server

  #5  
Jun 23rd, 2007
As for moving to MySql 5. I'd surely recommend it. We moved from 4 to 5 a while back, and noticed almost immediately an improvement in performance. Also 5 has transactions and stored procedures, the latter may help you with you admin tasks.

At the Php Conference here I learned that MySql 6 is going to have events, which will make your admin life a while lot easier. So maybe just wait for now and go for 6 when it is stable.

Jst my $0.02...
"Premature optimization is the root of all evil."
Donald Knuth
Reply With Quote  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 263
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: Moving database to new server

  #6  
Jun 23rd, 2007
This thread is old. Methinks she would have sorted it out by now
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
Reply With Quote  
Join Date: Jul 2006
Location: Remunj
Posts: 142
Reputation: pritaeas is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 16
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Junior Poster

Re: Moving database to new server

  #7  
Jun 24th, 2007
You're right, didn't even notice the date... mea culpa.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 11:16 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC