Web Developement
Now Reading
Restore a MySQL Database From the Command Line

Restore a MySQL Database From the Command Line

by Adrian RandallJanuary 24, 2016

A lot of developers who are new, or have been mainly doing specialised development (eg just front end or backend) have not had to restore databases before. Or if they have they are able to use MySQL Workbench which helps significantly with database administration.

The problem comes when you’re using a remote server which only has SSH access or the backup of the database is too big to open in MySQL Workbench to execute and restore the content.

So what do you do? Basically the same process of creating a database in MySQL Wordkbench or phpMyAdmin can be replicated from the command line easier than you think.

We assume you have MySQL installed and know the root username and password and are running Ubuntu or Mac OSX or a Linux variant…this won’t work for Windows but the theory will be the same.

  1. Login to MySQL from the command line:

mysql -u root -p

You will be prompted for your password

  1. Create your new database:

create database myNewDatabase;

If you already have a database you can skip this step.

  1. Exit out of MySQL from the command line by typing:


  1. From here we assume you have a database backup in the current folder you’re in called ‘myDatabaseBackup.sql’. From the bash command prompt type:

mysql -u root -p myNewDatabase < myDatabaseBackup.sql;

You will be prompted for your password

  1. That’s it, you’re done.

Tip: If your backup has an extension of .zip or anything else this command will still work.



About The Author
Adrian Randall
I'm a digital marketing specialist, love working on digital business and coding on just about anything. I'm the founder of Arcadian Digital and this site shares some of our knowledge and practices.

Leave a Response