Your WordPress database holds your posts, pages, settings and users. WP-CLI makes it easy to save a copy before you make changes, and to put it back if you need to.
Export (back up) your database
wp db export ~/wp-backup-$(date +%F).sql
This saves a copy of your database in your home folder, with today’s date in the file name, for example wp-backup-2026-10-01.sql.
Import (restore) a database
wp db import ~/wp-backup-2026-10-01.sql
Replace the file name with the one you want to restore.
Other useful commands
| Command | What it does |
|---|---|
wp db size --human-readable | Shows how big your database is |
wp db check | Checks your database tables for errors |
wp db optimize | Tidies up your database tables |
Tidy up old backups
Database copies use space in your hosting plan. List them, and delete ones you no longer need:
ls -lh ~/*.sql
rm ~/wp-backup-2026-10-01.sql
You can also download a copy to your computer using FTP or the File Manager.