How to restore a MySQL backup

SimpleBackups founder

Laurent Lemaire

Co-founder, SimpleBackups

October 20th, 2020

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.

Table of Contents

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

Stop worrying about your backups.
Focus on building amazing things!

Free 7-day trial. No credit card required.

Not convinced yet? Need help?
Get in touch via chat or at [email protected]

Customer support with experts
Security & privacy first
Service that you'll love using