# 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/>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://helpcenter.xopero.com/xopero-one-en/backup-and-recovery/workstations-and-servers/database-backup-recovery/restoring-mysql-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
