How to restore a MySQL backup

Introduction

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.

Prerequisites

  • 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:

  1. Create a new MySQL database where you will restore your backup, or use an existing database.
  2. 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

Notes:

  • 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.


тнаBack to blog

Ready to automate your backups?

Sign up for FREE. Get started in less than one minute.

Secure your backups

No credit card required. Free 7-day trial.