Unable to run some wp-cli DB commands

Issue Summary

Some wp db ** commands don’t work some do.


When I start any site, right click open site shell and execute:

  • wp db check
  • wp db export (it was a problem in the past apparently)

Gives error:

  • wp db query "SHOW TABLES;" (any query)
  • wp db reset --yes
  • wp db clean --yes

The error itself:

So when I run wp db reset --yes --debug the error reads as follows:

Debug (bootstrap): Running command: db reset (0.163s)
Debug (db): Final MySQL command: /usr/bin/env mysql --no-defaults --no-auto-rehash --batch --skip-column-names --execute='SELECT @@SESSION.sql_mode' --host='localhost' --user='root' --default-character-set='utf8' (0.166s)
Error: Failed to get current SQL modes. Reason: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

When the command -found in the debug output- is fun manually it also gives the error.
It does work when appending --socket=PATHGIVENBYLOCAL (and -proot cli handles that by itself).
Or when I run the command and remove the --no-defaults flag.
Not sure if this is helpfull…

System Details

I’m on Local 6.1.0 (I only started on this today, so I havn’t tried other versions)
my Laptop runs Ubuntu 21.04

This was an issue with WPCLI and I filed a bug report here:

It looks like a fix may have been merged last night, so it’s likely that many of these will work in an upcoming release of WPCLI!

I feel like this command should work though, I know that I use it often, even on my Ubuntu 21.04 machine. What version of PHP and MySQL are you using?

On the local WP it’s php7.4 and mysql 8.0.16
Ubuntu also has php7.4 and no mysql at all, maybe that’s a thing…

I also found that issue and the pull associated.
There also appears to be a core issue involved.

I’ll guess I’ll wait for that.

As per the WordPress core documentation, and since Local WP app uses MySQL sockets, consider modifying your wp-config.php to include the use of MySQL Sockets.


If your host uses Unix sockets or pipes, adjust the DB_HOST value in the wp-config.php file accordingly.

define( 'DB_HOST', '' ); // or 
define( 'DB_HOST', 'localhost:/var/run/mysqld/mysqld.sock' ); // or 
define( 'DB_HOST', 'example.tld:/var/run/mysqld/mysqld.sock' );

Replace: /var/run/mysqld/mysqld.sock with the socket or pipe information provided by your host.

You can find the MySQL socket for your current local site here:
Local WP App → Local Sites → Install Name → Database Tab → Socket.

Copy/paste that into your DB_HOST constant definition in your wp-config.php

define( 'DB_HOST', 'localhost:/Users/%%USERNAME%%/Library/Application Support/Local/run/%%INSTALL_ID%%/mysql/mysqld.sock' );

1 Like

Thanks this helps a lot :slight_smile:

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