> For the complete documentation index, see [llms.txt](https://helpcenter.xopero.com/xopero-one-en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://helpcenter.xopero.com/xopero-one-en/backup-and-recovery/workstations-and-servers/database-backup-recovery/restoring-mysql-database.md).

# Restoring MySQL database

#### 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](/xopero-one-en/backup-and-recovery/workstations-and-servers/file-level-backup-recovery.md). If your database was backed up using an **image-level backup**, use granular recovery to restore it as described in [this article](/xopero-one-en/backup-and-recovery/workstations-and-servers/image-level-backup-recovery/granular-recovery.md).

{% hint style="warning" %}
**Xopero** recommends restoring the database files to their original directory to avoid potential permission issues in a different location.
{% endhint %}

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](#useful-links-and-items).

{% hint style="info" %}
This guide uses the **MySQL** command-line utility.
{% endhint %}

{% stepper %}
{% step %}
To restore the database, log in to the database server using the following command:

```sql
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
  {% endstep %}

{% step %}
Next, type:

```sql
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:

```sql
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.
{% endstep %}

{% step %}
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:

```sql
SOURCE PATH_TO_FILE
```

{% endstep %}
{% endstepper %}

***

## Useful links and items

{% embed url="<https://dev.mysql.com/downloads/utilities/>" %}
