Error establishing database connection using wp-cli and xampp

714 Views Asked by At

I've got everything to work with WP-CLI on Windows running XAMPP. Or so I thought. When I try to execute the following command:

wp rewrite structure '/%postname%/'

I get the following error:

Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we canÔÇÖt contact the database server at localhost. This could mean your hostÔÇÖs database server is down.

I've read that the PHP used needs to be correct (a usual explanation for this problem). Running wp --info yields the following results.

$ wp --info
PHP binary:     C:\xampp\xampp-5.6.24\php\php.exe
PHP version:    5.6.24
php.ini used:   C:\xampp\xampp-5.6.24\php\php.ini
WP-CLI root dir:        C:\lib\wp-cli
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.0.0

I think that this looks correct. I can access the db from a browser, use WP normally, and even perform database commands using wp-cli. But for some reason, the rewrite command gives an error (as stated above). The fun thing is that it actually changes the permalink option, but I'm afraid that since it gives an error some other action is not performed correctly.

Changing the credentials in wp-config.php makes me unable to run db commands, so clearly it works at some level.

What might be wrong? I'm pretty clueless here!

The database is set up by using wp-cli and is accessed using the root account.

1

There are 1 best solutions below

0
On BEST ANSWER

It turned out to be a bug in wp-cli, which the author is now working on.