# WP-CLI support with MySQL sockets in Local 5

**URL:** <https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116>\
**Category:** Support\
**Tags:** wp-cli, mysql\
**Created:** [January 28, 2021, 4:57pm UTC](https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116 "2021-01-28T16:57:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kvnblckdsk](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@kvnblckdsk](https://community.localwp.com/u/kvnblckdsk)\
**Post date:** [January 28, 2021, 4:57pm UTC](https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116/1 "2021-01-28T16:57:51Z")

</div>

So since Local switched to a MySQL socket connection I’m unable to get WP-CLI working. WP-CLI tries to connect to the database using the values in `wp-config.php`, which is “localhost” for the server instead of a socket and throws the `Error: Error establishing a database connection.` error. Is there any way to support WP-CLI commands with the new socket connection type for MySQL?

---

<div class="post-metadata">

**Author:** ![kvnblckdsk](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@kvnblckdsk](https://community.localwp.com/u/kvnblckdsk)\
**Post date:** [March 16, 2021, 9:42am UTC](https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116/2 "2021-03-16T09:42:38Z")

</div>

I found out how. In wp-config.php change the

```auto
define('DB_HOST', 'localhost');

```

to

```auto
define('DB_HOST', 'localhost:/path/to/the/socket.sock');

```

and it works 🙂

---

<div class="post-metadata">

**Author:** ![ben.turner](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/ben.turner/32/5366_2.png) [@ben.turner](https://community.localwp.com/u/ben.turner)\
**Post date:** [March 17, 2021, 9:17pm UTC](https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116/3 "2021-03-17T21:17:44Z")

</div>

wpcli should be working with the latest (5.x) versions of Local. Are you right-clicking on the site in Local and selecting “Open Site Shell?”

This will open a terminal and configure the various environmental variables that need to be set in order to connect to the correct site.

---

<div class="post-metadata">

**Author:** ![henscu](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/henscu/32/9054_2.png) [@henscu](https://community.localwp.com/u/henscu)\
**Post date:** [March 25, 2021, 12:22am UTC](https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116/4 "2021-03-25T00:22:48Z")

</div>

Thanks, Ben.

Just one modification to your instructions is required for those of us who are using Local with [Roots Bedrock](https://roots.io/guides/local-bedrock-development-with-local-by-flywheel/) WordPress.

When using Bedrock with Local, the Bedrock **wp** directory is in a different location from the standard Local setup, but wp-cli works if I just add the path to Bedrock’s wp directory using the **–path** parameter as shown below… (the command is being run from the …/app/public directory that Site Shell opens in)…

```
       wp db tables --path='../bedrock/web/wp'
```

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/system/32/1_2.png) [@system](https://community.localwp.com/u/system)\
**Post date:** [June 23, 2021, 12:22am UTC](https://community.localwp.com/t/wp-cli-support-with-mysql-sockets-in-local-5/24116/5 "2021-06-23T00:22:49Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
