Joyent

Backing up and Restoring a MySQL database

Backing up a MySQL database

To backup a MySQL database, do the following.

Using Virtualmin

  1. Sign in to Virtualmin (see Account Logins and Important URLs).
  2. Select a domain from the drop-down in the left-hand navigation (your main domain should be already selected when you first login to Virtualmin).
  3. Click Edit Databases. You should now see a list of your current databases on the Edit Databases page.
  4. Select the MySQL database you want to back up from the left-hand column under Database name and click Manage...
  5. Click Backup Database. You should now see the Backup Database page.
  6. For Backup to file, enter a location on your account where you want the data base to be saved and a suitable filename (e.g., /users/home/yourusername/dbbackup). Clicking ... will allow you to browse to a suitable location on your account.
  7. Select whether you want all tables to be saved, or just a few specific ones. If you want to back up everything, then just leave All tables selected
  8. For Add drop table statements to backup?, leave it as No unless you need a drop table statment
  9. Leave Character set for backup as the default
  10. Leave Backup compatability format as the default
  11. And for Compression format decide whether you want to compress your backup to save space.
  12. Now, click Backup Now. You should now see a page confirming a successful backup and your database should be saved in your desired location

And that’s it, you’ve just made a backup of your MySQL database!

Using the Shell

  1. cd to the directory where you wish to store the data.
  2. Enter:
    mysqldump --compress --user=USERNAME -p --opt --lock-tables=false --skip-add-locks --skip-extended-insert DATABASE > DATABASE.sql

Replace the values in CAPS with the specific values for your account. You can also change the character set, if you wish. The file can be compressed for faster transfer with:

gzip DATABASE.sql

Restoring up a MySQL database

To backup a MySQL database, do the following.

Using Virtualmin

  1. Sign in to Virtualmin (see Account Logins and Important URLs).
  2. Select a domain from the drop-down in the left-hand navigation (your main domain should be already selected when you first login to Virtualmin).
  3. Click Edit Databases. You should now see a list of your current databases on the Edit Databases page.
  4. Select the MySQL database you want to back up from the left-hand column under Database name and click Manage...
  5. Click Execute SQL. You should now see the Execute SQL page.
  6. Near the bottom of the page either enter a location on your account where you want the data base to be restored from for From local file (clicking ... will allow you to browse and select the file) or select From uploaded file and click Choose File to select a file from your local machine.
  7. For File format, leave it as Tab separated
  8. Now, click Execute. You should now see the Import Data page confirming a successful restoration and your MySQL database.

And that’s it, you’ve just restored your MySQL database!

Using the Shell

  1. cd to the directory where your sql data is stored.
  2. Enter:
    mysql --user=USERNAME --password=PASSWORD DATABASE < DATABASE.sql

If you have the file gzip’ed, gunzip it first, or change the command above to:

zcat DATABASE.sql.gz | mysql --user=USERNAME --password=PASSWORD DATABASE

 
accelerators/kb/backing-up-databases.txt · Last modified: 2008/01/26 20:26 by alexbcoles
 
Recent changes RSS feed Creative Commons License Driven by DokuWiki