How can I Backup and Restore a MySQL database?

Article Details
URL: https://my.dotcomhost.com/support/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=39
Article ID: 39
Created On: 19 Jan 2010 09:37 AM

Answer phpMyAdmin

You can use phpMyAdmin from within the Plesk control panel to backup and restore your database if it is less than 10MB. If your database is larger than that please skip to command line option.

BACKUP:

1. Click databases in the Plesk control panel.

2. Click on the name of the database you'd like to backup.

3. Click DB WebAdmin. This will open a new browser window. Please disable your pop up blocker or allow from *.dotcomhost.com.

4. Select the database you'd like to back up from the column on the left.

5. Click on Export from the top set of tabs.

6. Select the tables from the list that you would like to backup. If you want to backup the entire database click Select All.

7. Select Structure and data from the bullet list.

8. Selection boxes:
9. Click the Go button, then when prompted save the file to your local computer.

RESTORE:

1. From the column on the left select the database that you want to restore to. If it doesn't exist you must first create it. This can be accomplished in the Plesk control panel.

2. Click on Import from the top set of tabs.

3. Click the Browse button next to Or Location of the textfile: near the bottom.

4. Browse to the local backup and click Open.

5. Click the Go button .

Command Line

This method works regardless of the size of your database. You must have SSH access to your domain. If you do not already have SSH access to your domain, you my submit a request to support to have this service added to your account for $5 per month.

BACKUP:

1. Log into your server via SSH and cd into a directory where your user has write access such as the /private/ directory.

2. Enter the following command: mysqldump --add-drop-table -u username -p dbname > dbname.sql
3. Enter your MySQL password at the prompt. If you don't know it you can reset it in the Plesk control panel
4. Use FTP to download the file to your local computer for backup.

RESTORE:

1. Use FTP to upload the file to your server, the /private/ directory is the best place for this.

2. Log into your server via SSH and cd to the directory where you've uploaded the file.

3. Enter the following command: mysql -u Username -p dbname < dbname.sql
4. If you have a zipped backup of your database you can use this line instead: gunzip < dbname.gz | mysql -u username -p dbname
5. Enter your MySQL password at the prompt. If you don't know it you can reset it in the Plesk control panel.