Backing up and Restoring MySQL
Submitted by BinksUK on
I'm an incredibly dim person at times, if you don't spell it out to me the penny just doesn't click. Been trying to figure out for ages how to backup all of my databases and then transfer them to another machine. It turns out it's so simple nobody has bothered to document the whole process (that I could find). I figure if I write it down here I shall know for next time...
On machine with the databases, open cmd and type...
mysqldump -u[username] -p[password]--all-databases> alldatabases.sql
or for individual db's
mysqldump -u[username] -p[password] [dbname] > [filename]
I find this only works if I don't leave a space between -u and the username and similarly for the password... it might just be a quirk in my setup though.
Transfer the dumped file over to the new machine (I found the file in my folder in Documents and Settings (can't see a reason why you can't change the filename to point to a specific location but I couldn't be bothered!))
On the new machine open and cmd and type...
mysql -u[username] -p[password] < [backupfile]
or for individual db's
mysql -u[username] -p[password] [dbname] < [filename]
Hey presto, all my databases have been moved
If you google you'll find much more info including how to compress your backups to make them smaller.