Backing up and Restoring MySQL

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 Smiling

If you google you'll find much more info including how to compress your backups to make them smaller.

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.