WP-CLI Database
questions
Answers to common questions about importing and exporting WordPress databases with WP-CLI. Covers wp db import behavior, credentials, failed imports, and when to run wp core update-db.
Does wp db import drop the existing database before importing?
Yes. WP-CLI runs the .sql file against the current database, which typically begins with DROP TABLE IF EXISTS statements for each table. The result is a clean replacement of the existing data, not a merge. This is why the export step before import is critical — anything not in the backup file will not exist after the import.
Used in
- Database Export and Import Practice Case
How do I know the backup I am importing is from the right environment?
Run grep 'siteurl' backup.sql | head -5 before importing. The siteurl value in the dump shows which site and domain the backup came from. If it shows a localhost or staging URL, you will need to run wp search-replace after the import to fix all domain references.
Used in
- Database Export and Import Practice Case
What credentials does wp db import use?
WP-CLI reads the database host, name, user, and password directly from wp-config.php. You do not need to pass credentials on the command line. This is why wp db import backup.sql works without any additional flags.
Used in
- Database Export and Import Practice Case
What if the import fails halfway through?
The database may be in a partially restored state. First, check the error message — it usually points to a specific table or SQL statement. If the import file is valid, try running it again (WP-CLI’s import is generally idempotent for standard WordPress dumps because each table is dropped before recreating). If the file itself is corrupted, you need an earlier backup.
Used in
- Database Export and Import Practice Case
What is the difference between wp db export and a manual mysqldump?
wp db export is a thin wrapper around mysqldump that reads credentials from wp-config.php automatically. The resulting .sql file is compatible with wp db import and standard MySQL import tools. The main advantage over raw mysqldump is that you do not need to manually pass host, user, password, and database name on the command line.
Used in
- Database Export and Import Practice Case
Why run wp core update-db after importing a backup?
The backup captures the database state at the time it was made. If WordPress core or any plugin was updated after that backup, the current PHP code expects a newer schema. wp core update-db applies any pending ALTER TABLE and schema changes that the code expects but the restored database does not yet have.
Used in
- Database Export and Import Practice Case
Smart FAQ Management
4WP FAQ
Not just another FAQ block. A smart wrapper that adds intelligence
without breaking your design.