brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp db import loads a SQL dump into WordPress with the wp-config credentials

WordPress
~/tips/tip-wordpress-db-import-stdin

wp db import backup.sql

Restores a database dump without typing the database user, password or host.

Restoring a dump with the mysql client means looking up the user, password and host first. wp db import reads them from wp-config.php.

A plain file:

wp db import backup.sql

And a compressed one, straight from a pipe. The - tells it to read from standard input:

gunzip -c backup-2026-11-30.sql.gz | wp db import -

I like how that pairs with wp db export - | gzip on the backup side. No temporary uncompressed file on disk.

By default it turns off unique and foreign key checks during the import, which makes big dumps load faster. --skip-optimization keeps them on. It also strips SQL modes that WordPress itself does not use, unless you pass --skip-sql-mode-compat.

Here’s the part that can hurt: the command just runs the SQL in the file. A normal wp db export dump contains DROP TABLE IF EXISTS for each table, so importing it replaces your current tables completely. Everything written since the dump was made is gone. Make a fresh export of the current state first, so you can go back if you grabbed the wrong file.

Further reading: wp db import, wp db export

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link