How do I import a MySQL database with SSH?
This article will show you how to import a MySQL database into your Virtual Private Server using SSH.
If you’d rather use an SSH connection to import an SQL backup file into your database (rather than phpMyAdmin), this can be done by following the steps outlined below:
Please note: the following article was originally created for our current generation of Virtual Private Servers. As such, these instructions may not be relevant to our previous generation of Virtual Private Servers.
Important: before you get started, you will need the following:
Start by uploading your SQL backup file to your server via FTP or File Manager.
Once you’ve done this, connect to your server via SSH.
Enter the command ls, which will list all your server’s files and folders.
Next, enter the command cd, followed by ../ to find the directory you uploaded the backup file in.
Once you’ve found this directory, connect to MySQL by entering this command but DON’T press Enter on your keyboard:
mysql -h hostname -P port -u username -p database < backup.sql
Please note: if your host uses the value localhost, you can exclude -h hostname. Similarly, if you have a standard port value of 3306, you can exclude -P port.
Next, you’ll need to change the following values:
- hostname: your hostname.
- port: your MySQL port number (3306 by default).
- username: the username for your database.
- database: the name of the database you wish to export.
- backup.sql: the name of your backup file.
Once you’ve done this, press Enter on your keyboard.
Next, enter the password for your database user into the provided field and then press enter on your keyboard.
Please note: this field may not always appear so please enter your password even if you don’t receive anything.
After a few moments, your SQL backup file will be imported into your database.