I am aware of WP-CLI's many database interaction functions via "wp db" and its functions for generating wp-config files via "wp config" - However I cannot find a way of using WP-CLI to modify existing database name, username and password settings in wp-config.

I am migrating multiple sites, and the ability to do this would be a time saver.

I am aware that wp config can launch vi editor (wp config edit), but I am looking for a way to pass the database name, username and password TO WP-CLI to have it do the job for me. Possible?

1 Answer 1


You can use wp config set to update any existing value in wp-config or to add a new value:

wp config set DB_NAME some_db_name
wp config set DB_USER some_db_username
wp config set DB_PASSWORD you_secret_value_pass

See https://developer.wordpress.org/cli/commands/config/set/

Keep in mind that values are case sensitive, so if you do wp config set db_name some-db, it will add a NEW value rather than update the value for DB_NAME.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.