Skip to main content

Backing Up and Restoring a Database

databases, backup, restore, mysql, import, export 0 Was this answer helpful?

Regular database backups protect you from data loss due to software errors, hacking, accidental deletion, or failed updates. There are several ways to back up and restore databases in cPanel.

Please note: Screens and options may vary slightly depending on your cPanel version and hosting plan.

Backing Up via phpMyAdmin

  1. Go to phpMyAdmin in the Databases section of cPanel.
  2. Select the database from the left sidebar.
  3. Click the Export tab.
  4. Choose Quick (for a standard SQL dump) or Custom (for more control over the export).
  5. Click Go to download the .sql file.

Backing Up via cPanel Backup

  1. Go to Backup in the Files section.
  2. Scroll to Download a MySQL Database Backup.
  3. Click the database name to download the SQL dump.

Backing Up via SSH (Command Line)

mysqldump -u username_dbuser -p username_database > backup_filename.sql

Replace username_dbuser and username_database with your actual database user and name. You'll be prompted for the password. This method handles large databases more reliably than phpMyAdmin.

For compressed backups:

mysqldump -u username_dbuser -p username_database | gzip > backup_filename.sql.gz

Restoring via phpMyAdmin

  1. Open phpMyAdmin and select the database.
  2. If restoring to a fresh database, ensure the database exists and is empty. To empty a database, select all tables and choose Drop from the "With selected" dropdown.
  3. Click the Import tab.
  4. Click Choose File and select your .sql or .sql.gz backup file.
  5. Click Go.

Restoring via cPanel Backup

  1. Go to Backup in the Files section.
  2. Scroll to Restore a MySQL Database.
  3. Click Choose File, select your .sql file.
  4. Click Upload.

Restoring via SSH (Command Line)

mysql -u username_dbuser -p username_database < backup_filename.sql

For compressed backups:

gunzip < backup_filename.sql.gz | mysql -u username_dbuser -p username_database

Tips

  • Test your backups periodically by restoring them to a test database. A backup you can't restore is useless.
  • Automate backups with a cron job for peace of mind.
  • Always back up your database before running application updates (WordPress core, plugins, themes, etc.).
  • Store backups offsite — don't only keep them on the same server as the database.
  • For very large databases, the command-line approach is the most reliable and fastest.

What Next?

Related Articles

knowledgebasedidyoufindanswer