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

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:eval(ez_write_tag([[728,90],’howtoforge_com-box-3′,’ezslot_4′,106,’0′,’0′]));

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!eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-3′,’ezslot_1′,121,’0′,’0′]));

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.

Example:

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

Leave a Reply