Acorn Error establishing a database connection

Hi there,
I’m eager in starting to use Acf Composer, but I’m having problems getting Acorn to work in my theme…

Just running wp acorn from my sage10 theme already results in this error:

Warning: mysqli_real_connect(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in /path/to/my/project/site/web/wp/wp-includes/wp-db.php on line 1653

Error: `Access denied for user 'user'@'localhost' (using password: YES)`

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.

Are you sure you have the correct username and password?

Are you sure you have typed the correct hostname?

Are you sure the database server is running?

If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums. `Access denied for user 'wearee'@'localhost' (using password: YES)`

In my web folder I have added the correct credentials to the wp-cli.yml file and running wp @development from my theme folder gives no errors?

Clearly I’m missing something, but don’t know what?
Thanks for any pointers!

p.s. Im still on Composer 1.10.15, is 2.* required for Acorn?

Do you see this error only when you run wp acorn? Or with any wp command?

wp @development

Runs just fine, so I think it’s acorn related?
Any of the acf-composer commands fail with same database error:

wp acorn acf:field Example

Do you see the same behavior when you don’t use aliases? i.e. if you ssh into your vm and run the same commands?

vagrant@example:/srv/www/example.com/current/web/app/themes/sage$ wp acorn acf:field Example

Runs without any errors:

🎉 Example field successfully composed.
     ⮑  app/Fields/Example.php

Are you supposed to run these acf-composer commands inside the vm?

1 Like

I can’t answer that question w/ authority because I don’t know a great deal about them, but my guess is that because the wp acorn commands load (I believe) the whole Acorn thing when they start up, some part of that is potentially attempting to call the database outside of the context of the WP CLI command–wp acorn is basically shoehorning the Laravel console (or parts of it at least) into the WP CLI framework.

I don’t know exactly how WP CLI aliases work internally, but my guess is whatever they do is not strictly compatible w/ how Acorn does the above. I’ve never run into the problem you’re having because I’m too lazy to set up aliases (and to be perfectly honest; I don’t entirely trust them for reasons I can’t explain) so I run all my WP CLI stuff inside of my VM.

Ah on further investigation, this does work directly from my local sage theme path:

# ~/Development/example.com/site/web/app/themes/sage
wp @development acorn acf:field Example

Were you previously running the wp acorn commands w/o the alias? Usually I try to run all wp commands “in” whatever environment my site actually exists in (i.e. if the site is in a VM, the commands should be run inside the VM). IME not doing that can lead to kind of odd errors (potentially including the one you described)–the wp commands are meant to interact with WordPress, and if they can’t access WordPress (distinct from being able to access the files that describe WordPress) then you’re using it outside of the intended context.

Jup :flushed:

Yes that totally makes sense! I was just looking at the docs and kind of assumed that it would work outside the vm… :thinking:

Thanks for your help!

This topic was automatically closed after 42 days. New replies are no longer allowed.