Wp-cli Error: Error establishing a database connection

Thereā€™s probably something ā€˜obviousā€™ that Iā€™m missing. Just starting out with roots .

I installed wp-cli globally and Iā€™m able to run
theme-folder$ wp --info

If I try to run wp --help get the following error:

theme-folder$ wp help
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /Users/me/examples.com/site/web/wp/wp-includes/wp-db.php on line 1488
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Users/me/roots/examples.com/site/web/wp/wp-includes/wp-db.php on line 1518
Warning: mysql_connect(): No such file or directory in /Users/me//examples.com/site/web/wp/wp-includes/wp-db.php on line 1518

Looking at your error, it doesnā€™t seem like PHP thinks that MySQL is installed

Okay, thanks for your help! I followed the trellis steps in the doc and my wpdev site and vagrant environment are up and running. I probably missed a step.

I donā€™t know what your set up is. Which docs are you reading? Are you using Trellis? If so, you need to SSH into the vagrant box for any database commands to run, and thatā€™s the vast majority of wp commands.

Otherwise, if you have it set up with MAMP or something like that, you would need your PHP and MySQL set up correctly.

Edit sorry saw you said ā€œtrellisā€ in your second message. Yes, run vagrant ssh and cd /srv/www/{your-site.com}/current and run your wp-cli commands there.

2 Likes

Awesome! That worked. Thanks again. :sunny:

I have exaclty the same issue. Does that mean that I canā€™t run wp commands from my host OS? Never before I had troubles doing it.

Yes

I donā€™t believe you :wink:

1 Like

You can run some, but most wp commands basically load WP, and because they do, they will look at the database credentials and try to connect. At the moment, we canā€™t connect to the database remotely with the database credentials, so we canā€™t run quite a few wp commands from the host. Itā€™s been that way since the beginning, and almost all WP projects that use Vagrant.

2 Likes

Hi, Iā€™m a newbie and Iā€™m working on windows.

Iā€™m using Trellis.

From Cmder I run vagrant ssh.

I get this output

Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-31-generic x86_64)

Then I try to run a wp-cli command from /srv/www/{your-site.com}/ but I get the following error

Error: This does not seem to be a WordPress install.
Pass --path=path/to/wordpress or run wp core download.

Iā€™m totally confused. Iā€™ve never used wp-cli before and ssh either.

Any help would be appreciated.

Youā€™ll need to run wp-cli commands from the current directory, so /srv/www/{your-site.com}/current

2 Likes

Thanks @ben

Yes, now itā€™s working perfectly.