Home > Software design >  Can WP-CLI modify database connection details in an existing wp-config file?
Can WP-CLI modify database connection details in an existing wp-config file?

Time:11-24

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?

CodePudding user response:

The wp config subcommand can alter your wp-config.php file without trying to fire up the whole WordPress stack or open the database. So you could change, for example, your DB_HOST like so.

wp config set DB_HOST mariadb.example.com

It works for any define() in your config file.

It takes four of these set commands to modify host, database, user, and password, of course.

  • Related