This guide provides the steps required to make a backup or restore a backup of a MySQL or MariaDB database.
Create Backup of MySQL Database
This example shows you how to export a database. It is a good idea to export your data often as a backup in preparation for possible Disaster Recovery scenario.
- Login to your server as root user.
- Run the following command:
# mysqldump -u [username] -p [password] [database_name] > FILE.sql
Replace [username], [password] and [database_name] with your MySQL username, password and database name.
File FILE.sql now holds a backup of your database. You may download it to your local computer.
Restore Backup of MySQL Database
Here, we will import a database. These steps can be used to restore a database to previous version from backup or to import a database from an external source MySQL server.
- Login to your server as root user.
- Run the following command:
# mysql -u [username] -p [password] [database_name] < FILE.sql
Replace [username], [password] and [database_name] with your MySQL username, password and database name.
The FILE.sql is now imported into MySQL.