How to Restore a MySQL Database with Linux Shell

By | July 3, 2008

Today I will show a simple command that will allow you to restore a database from a previously made sql file. No matter, how the backup was done, if it has sql commands, you will restore it in the fastest possible way.

If your database backup file exceeds 10 megabytes, it’ll be very hard to restore it using usual panel options (I mean Directadmin, Cpanel, PhpMyAdmin, etc). If you have shell a access to your server, you may significally decrease the time necessary for backup restore. All you have to do id to upload this backup to an accessible location, and then to run a command:

mysql -ppassword -u user database_name -h localhost < path_to_sql_file

This command will start mysql database restore ptocess without prompting for a password. If you want to enter your password each time, you should leave -p option empty.

This is the fastest way to recreate your database using a dump file.