MySQL Backup and Restore

by Mike on December 4, 2009

in Ubuntu Servers

You can use the mysqldump utility to backup your databases.  The simplest way is to create the backup file in another directory.  Of course, you would want to have the backup directory on another harddrive, in case the main database harddrive were to go bad.

mysqldump -p -u root –opt virtual > /backup/virtual-2010-10-24

Enter password:
cd /backup

To restore a database from a backup, invoke the “mysql” command, with the backup file as its input:


mysql -p -u root virtual < /backup/virtual-2010-10-24
Enter password:

Note that the only directory path that you have to specify is the one where you’re storing the backups.  The “mysql” and “mysqldump” programs know where the actual databases are stored.

You could also transfer the backup file to another MySQL server with the scp command:

scp virtual-2010-10-24 root@

Then, on the machine that you just transferred the file to, create an empty database to load the backup file into:

mysql> create database virtual;
Query OK, 1 row affected (0.01 sec)

mysql> quit

Finally, load the backup file into the empty database:

mysql -p -u root virtual < ~/virtual-2010-10-24
Enter password:

Previous post:

Next post: