Bug Summary
wp db query fails when run through the new localwp cli command with “Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’”. Other WP-CLI commands, including db check, work fine against the same running site.
Steps to reproduce
-
In Local 10.2, turn on the CLI under Preferences → Advanced → “Install Local CLI”.
-
Start a site whose
wp-config.phphas the defaultdefine( 'DB_HOST', 'localhost' );. -
Run
localwp cli <site> -- db query "SELECT 1". -
It fails with exit code 1:
Error: Failed to get current SQL modes. Reason: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) -
For comparison,
localwp cli <site> -- db checkandlocalwp cli <site> -- eval 'echo get_bloginfo("version");'both succeed.
It looks like WP-CLI runs the mysql client with --no-defaults for this command, so it never reads the socket path in Local’s my.cnf. With DB_HOST set to localhost, the client falls back to /tmp/mysql.sock, but the site’s real socket is at ~/Library/Application Support/Local/run/<site-id>/mysql/mysqld.sock. The same failure in the Site Shell was reported in Wp-cli’s wp db query fails to connect when executing SQL on the command line. Adding the socket path to DB_HOST in wp-config.php works around it, but that file is shared with other environments. Could localwp cli pass the site’s socket to WP-CLI, or configure WP-CLI so db commands find it?
Environment Info
- Operating system: macOS 26.6.2 (Apple Silicon)
- Site software: nginx 1.26.1, PHP 8.1.23, MySQL 8.0.35 (WP-CLI 2.12.0)
- Local version: 10.2.0+7022
Supporting info
Choosing not to attach my Local log because it seems to have a lot of references to private development information.