Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just got my new server setup and in the corner and am in the process of moving services over to it from my existing box. I need to move over mysql and apache.

What's the best way to move everything over? Just copy over all the apache directory roots and the sites (the config files) I'm assuming is the best/only way to get apache over, but with mysql I obviously want to keep all the passwords for things, so should I just backup and restore or can I make them talk to each and tell the one server to just suck data from the other one?

EDIT: I can afford to take the site down for 30 minutes or so, if that makes a difference.

share|improve this question
add comment

4 Answers 4

Learning to use mysqldump won't hurt and it will help you make backups of your databases and transfer them to another server too. Passwords and some other useful things live in database named mysql. A simple example:

mysqldump -u myuser -p mypassword mydatabase > dump.sql

Then just feed it to mysql anywhere else.

share|improve this answer
    
I used mysqldump to backup my db currently. –  Daniel Huckstep Jun 1 '09 at 23:45
add comment
up vote 3 down vote accepted

Building on what Gleb said, and what Google found for me:

mysqldump -u user -p password thedb | ssh user@newserver mysql -u user -p password thedb
share|improve this answer
    
This is a cool example, although if the database is huge and the link is small, dumping to a file and compressing would probably be a better option. Great example, though –  Matt Simmons Jun 2 '09 at 16:34
    
I probably should have mentioned this earlier, but the database is going between physical servers, which are on the same subnet connected by a Gigabit ethernet link, so it happened in less than 10 seconds each for all my databases. –  Daniel Huckstep Jul 9 '09 at 19:28
add comment

As Gleb said, using mysqldump is the easiest way (depending on the traffic on the database. Very heavy and mysqldump won't pick up some changes).

With apache, just rsync the directories across before-hand, then do it again when you're ready to do the switch. That way you minimize the size of the sync when it's crunch time.

You'll also want to do it before hand to make sure that your various configuration files were picked up and synced correctly (and that you got them all).

This isn't too complex, but it is good practice for bigger live migrations.

share|improve this answer
add comment

Building on Gleb & darkhelmet's snippet, I'd strongly recommend running mysqldump with --opt (depending on your version of MySQL, it might not be the default) to minimize the transfer amount, as well as a bunch of optimizations to the dump/import process.

Furthermore, as you say you want to keep the privileges / user tables, you may want to run with --all-databases.

Another option you have would be using MySQL's replication to (as you put it) suck data over. I'm guessing you don't have binary logging enabled (if you did, the process would be painless).

One of the most important points if using mysqldump is to make sure you run everything with the correct character set (using latin1 if you have utf8 data may cause some "interesting" issues).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.