WordPress WP-CLI 2 cheatsheet
WordPress WP-CLI 2: Database
7 common WordPress WP-CLI 2 tasks.
Restore the database
Import a SQL file into the database.
wp db import backup.sql
Caution: Overwrites tables with the same names. Export a backup first.
Preview a URL change
Show how many replacements a search and replace would make, without changing anything.
wp search-replace 'http://old.example' 'https://new.example' --dry-run
Change a URL everywhere
Replace a URL across the database. It handles serialized data safely, unlike a plain SQL replace.
wp search-replace 'http://old.example' 'https://new.example' --skip-columns=guid
Caution: Export a backup first, and run the --dry-run version to check the count.
Empty the database
Delete all tables in the database.
wp db reset --yes
Caution: Deletes every table and all content. --yes skips the confirmation prompt.