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

If your MySQL user has a password:

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]

Share this page:

3 Comment(s)

Add comment

Comments

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