Export and import a database with WP-CLI
WP-CLI is a command line tool that helps you perform different actions on your WordPress site. If you're comfortable with using SSH commands, you'll notice that WP-CLI has simplified commands created for WordPress sites. Here's how you can use the database export and import commands available to WP-CLI.
- 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 or Managed WordPress Hosting (steps 1-7).
Export the database with WP-CLI
- Connect to your hosting account with SSH.
- Use the bash command ls to list files and folders, and cd and ../ to move through directories until you're in the directory with your WordPress files.
- Enter the following command:
wp db export filename.sql
- In the command above, you should replace filename.sql with the name you want to use for the backup file.
You'll see a success message once the export is complete. Larger databases will take longer to export.
mysqldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespacesIn most cases, your database will have been exported successfully, despite seeing this error. But we recommend confirming the export by checking your database tables manually.
Import the database with WP-CLI
- Upload the SQL backup file to the folder with your WordPress files using FTP or File Manager.
- Connect to your hosting account with SSH.
- Use the bash command ls to list files and folders, and cd and ../ to move through directories until you're in the directory with your WordPress files.
- Enter the following command:
wp db import filename.sql
- In the command above, you should replace filename.sql with the actual name of your backup file.
You'll see a success message once the import is complete. Larger databases will take longer to import.
More info
- If you don't have WP-CLI available on your server, you can use standard SSH commands to export and import databases.
- You can also export and import your database in phpMyAdmin.
- Find and replace for WordPress with SSH