How do I restore a MySQL database from an sql dump?

This article shows how to restore MySQL databases on the commandline easily. If your MySQL user has a password, then use this command:

mysql -h localhost -u [MySQL user, e.g. root] -p[database password] [name of the database] < [name of your sql dump, e.g. sqldump.sql]

Please note:  there's no space between -p and the password!

If there's no password:

mysql -h localhost -u [MySQL user, e.g. root] [name of the database] < [name of your sql dump, e.g. sqldump.sql]

The above commands are compatible with all Linux distributions incl. CentOS, Fedora, Arch Linux, OpenSuSE, etc.

On Debian and Ubuntu you can use the debian-sys-maint login to restore the MySQL database, so you dont have to remember the MySQL password.


sudo mysql --defaults-file=/etc/mysql/debian.cnf [name of the database] [name of your sql dump, e.g. sqldump.sql]

Share this page:

3 Comment(s)

Add comment


From: at: 2010-10-12 23:22:52

That's much faster and easier than using import in phpmyadmin or another mysql manager.

From: Das_omen at: 2011-03-25 14:05:49

I have done this in many ways... with mysqldump , mysqlimport and phpmyadmin... I'm running an Ubuntu 10.04 server with apache2 / mysql installed... 

 When I try to import the server does nothing, no error and no responses... Any ideas what might be the problem!?

From: Kartik Grover at: 2015-01-08 13:04:28

The following example takes a backup of  all the database of the MySQL instance.

# mysqldump -u root -ptmppassword sugarcrm > sugarcrm.sq