Import MySQL database with SSH
A Secure Shell (SSH) connection can be used instead of phpMyAdmin to import an SQL backup file to your database. It's an advanced method that can help when importing large SQL files and can be necessary when using Self-Managed VPS or Dedicated Servers since they don’t have phpMyAdmin installed.
Required: You'll need the following to complete these steps:
- An SSH app. We suggest PuTTY for Windows, or Terminal for macOS.
- Your FTP details. If you don’t have them already written down, you should find your FTP host, username, and password:
- For your FTP host, you can use either your domain name or your IP address.
- You can find your FTP username and password in your hosting account for Linux Hosting with cPanel, Windows Hosting with Plesk, or Managed WordPress Hosting (steps 1-7).
- Your database details. If you don’t have them already written down, you should find your database name, username, hostname, and password:
- If you use Linux Hosting with cPanel, localhost is always your database hostname, and you can find other database details in your hosting account.
- If you use Managed WordPress Hosting or Windows Hosting with Plesk, visit your hosting account to find all database information.
Note: If you use WordPress, you can find the database details in your wp-config.php file.
- Upload the SQL backup file to the server using FTP or File Manager.
- Connect to your server or shared hosting account with SSH.
- Use the command ls to list files and folders, and cd and ../ to move through directories until you are in the directory to which you uploaded the backup file.
- Connect to MySQL using the following command:
mysql -h hostname -P port -u username -p database < backup.sql
Note: If you use localhost for your host, you should leave out–h hostname
and if you have a standard port (3306) you can leave out–P port
part of the command.- In the command above, you should replace:
- hostname with your hostname.
- port with your MySQL port number. Unless it's specified differently in your hosting account, your port is 3306.
- username with your username for this database.
- database with the name of the database you want to export.
- backup.sql with the name of your backup file.
- In the command above, you should replace:
- Select Enter on your keyboard.
- When Enter password: prompt appears, enter your password for that database user.
Note: The password will not be visible for security reasons, you won’t see anything as you type or paste.
- Select Enter on your keyboard.
The SQL backup file is now imported to your database.
More info
- Export MySQL database in SSH
- Here's how to import SQL files into a MySQL database if you don't want to use SSH.
- Here's how to export a MySQL database if you don't want to use SSH.