Export MySQL database in SSH
A Secure Shell (SSH) connection can be used instead of phpMyAdmin to export an SQL backup file for your database. It’s an advanced method that can help when exporting large SQL files and can be necessary when using Self-Managed VPS Hosting since they don’t have phpMyAdmin installed.
Note: If your site is hosted on one of the Managed WordPress hosting plans, you must use WP-CLI instead of SSH.
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 Web Hosting (cPanel) or Windows Hosting with Plesk.
- 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 WordPress, you can find the database details in your wp-config.php file.
- If you use Web Hosting (cPanel), localhost is always your database hostname, and you can find other database details in your hosting account.
- If you use Windows Hosting with Plesk, visit your hosting account to find all database information.
- Connect to my hosting account with SSH (Secure Shell).
- Use the command ls to list files and folders, and cd and ../ to move through directories until you are in the directory in which you want to save the backup file.
- Connect to MySQL using the following command:
mysqldump -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 you want to use for the 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.
Your database is exported to the SQL file you named in Step 4 and is ready for you to download to your local computer.
More info
- Import MySQL database with SSH
- You can also export and import your database in phpMyAdmin.