This tutorial will show you how to restore a MySQL database via SSH
Sometimes you will have a database backup that is too big to restore over a web interface. The best way to restore large SQL backups is through SSH, and all it takes is one command. This tutorial will show you how.
First of all, connect to your server via SSH and login as root/elevate yourself to root status. Here is the command we are going to use:
mysql -u user -p password -h host database_name < backupfile.sql
You need to change the bold sections. A brief explanation of each:
- user: The user who has access to the database you are importing data into
- password: Password of the user
- host: The database host. This is usually localhost
- database_name: Name of the database you want to import data into
- backupfile.sql – Name/location of the backup file you want to import.
Here is a proper example:
mysql -u john -p johnspass -h localhost johns_db < /home/john/backups/backup.sql
In this example, we are importing the file backup.sql into the database johns_db, using the user john, and the database host is localhost.
This could take a while depending on the size of the database. Once you are returned to the command line, the import has been completed. It is a good idea to check in phpMyAdmin or a similar tool to make sure that the database imported correctly.
If you want to learn how to backup a database over SSH, take a look at this tutorial.