Restoring MySQL database

This article explains how to restore a MySQL database from a backup.

MySQL database can be restored to its original location or to a new temporary directory.


How to restore MySQL database from backup

The first step in restoring a MySQL database from backup is to restore the database files from storage to a temporary directory. These files will then be imported into the MySQL database environment.

To restore files backed up using a file-level backup plan follow this guide. If your database was backed up using an image-level backup, use granular recovery to restore it as described in this article.

Once the database files are restored, the next step is to import them into the MySQL environment. To restore the database to the MySQL server, use a database management tool.

This guide uses the MySQL command-line utility.

1

To restore the database, log in to the database server using the following command:

mysql -h SERVER_ADDRESS -u USER -p
  • SERVER_ADDRESS — the address of the MySQL server where the database will be restored

  • USER — the username of the database user

2

Next, type:

USE DATABASE_NAME
  • DATABASE_NAME — the name of the database where the dump file will be restored

‼️ If the corrupted database still exists in MySQL, first drop it and recreate the database using the following command:

CREATE DATABASE DATABASE_NAME
  • DATABASE_NAME — the name of the database to be created for importing the database dump

After creating the new database, use the USE DATABASE_NAME command as described above.

3

The database backup is restored using the SOURCE PATH_TO_FILE command, replacing PATH_TO_FILE with the full path to the previously restored database file. The syntax is as follows:

SOURCE PATH_TO_FILE

Last updated