Skip to content

How to import database using WP-CLI in wordpress?

Updated 1 min read

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

  1. Upload the .sql file to your home folder.
  2. Open Terminal in cPanel (or SSH) and go to the WordPress folder:
    cd ~/public_html
  3. Back up the current database first, then import:
    wp db export ~/before-import.sql
    wp db import ~/backup.sql
  4. 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.

Related services

Web hosting

shared hosting on Virtualmin with NVMe storage, free SSL and email.

Managed cPanel VPS

cPanel included; we handle updates, security and monitoring.

Hire an expert

engineers per 15 minutes, per hour or per month, with no contract.

Was this answer helpful?

Still stuck? Open a ticket