So you already have your backup and decided to restore this on your MySQL database? In this article, we will tackle how to restore a MySQL backup using a simple command.
- MySQL installed
- MySQL user credentials
- A MySQL backup file; if you don't already have one, SimpleBackups provides an automated MySQL backup
- An existing database
How to restore a MySQL backup
The following steps assume you already have a MySQL backup:
- Create a new MySQL database where you will restore your backup, or use an existing database.
To restore the backup, use the command:
mysql -u [user] -p [database_name] < [filename].sql
- mysql - this is our main mysql program
- -u [user] - this flag is used to specify which user we will use to access the database
- -p - this flag signals that our user uses a password
- [database_name] - this will be our database's name where we will restore our backup
- < [filename].sql - this means that we will input(import) the contents of [filename].sql file into our [database_name] database
- After entering this command, you may be asked to enter the password for the MySQL user that you used.
- Please be careful when using an existing database that has records as this command will overwrite your existing database and end up losing your records.