Roots Discourse

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 @benword

Yes, now it’s working perfectly.