Updated: 28 September 2026 · Applies to: WordPress 7.1 with WP-CLI 2
WP-CLI can import an SQL file into your WordPress database, for example to restore a backup.
Steps
- Upload the
.sqlfile to your home folder. - Open Terminal in cPanel (or SSH) and go to the WordPress folder:
cd ~/public_html
- Back up the current database first, then import:
wp db export ~/before-import.sql wp db import ~/backup.sql
- If the site address changed, update it:
wp search-replace 'https://old.example.com' 'https://new.example.com' --skip-columns=guid
Note: Importing replaces the current tables with the ones in the file.