I’m having this very same problem right now: wpc-li can’t be used to run database commands.
Hi, I’m still having issues connecting to the Database. Can someone give me advice on the workarounds? in less tech terms. I’m a newbie to Local. Thanks!
Sorry my bad, try database:3306
I was finally able to make this work with some manual database edits via the Adminer. I was able to clear my tables, and import a new database through that interface.
Then, hopped back over to WP CLI for the search-replace function on my imported DB’s urls, so that was helpful but otherwise, yeah. The DB functionality still appears to be broken.
@flyjack do you have any insight as to when we might be able to expect a proper fix to this? I’m still seeing this error. ![]()
You might try something like the following in the site shell first.
SOCKET=$(mysqld --verbose --help | grep ^socket | awk '{print $2, $3, $4}');ln -sv $SOCKET /tmp/mysql.sock
I have tested this. The first part should get the socket and then symlink it to the expected location.
This is still an issue. I was hoping the recent update would fix but alas…
Will ya’ll ever be able to sort this out?
Did you try running the above command first?
I’ve managed to find a workaround which is not permanent but works. In the database tab in the Local there’s a path to the mysqld.sock. You just have to symlink /tmp/mysql.sock to that path.
ln -s /Users/my-username/Library/Application\ Support/Local/run/xxxxxxxxxxx/mysql/mysqld.sock /tmp/mysql.sock
If you’re on Mac, watch out for the space between Application\ Support. It has to be escaped. It gets me every bloody time 
That looks pretty good, almost there. Is there a way to escape spaces in the $SOCKET variable?
You should need to escape the variable. There are 2 commands on that line. The first gets the socket and he second symlinks it to the expected location.
In general to escape spaces in a command you would enclose it in “double quotes”
Is there any further update on the permanent fix for this issue?
I’m using Local 5.2.8+2771 on Ubuntu.
The symlinking solution posted by @afragen above works fine for me (thanks!) but you can only symlink one Local site’s socket file to /tmp/mysql.sock so if you are switching between multiple Local sites it doesn’t work or you have to keep deleting and re-creating the symlink for the relevant site.
You might need to change the symlink command above to ln -sfv To force an overwrite.
A shell alias as follows seems to work for me.
alias local-socket="SOCKET=\$(mysqld --verbose --help | grep ^socket | awk '{print \$2, \$3, \$4}');ln -sfv \$SOCKET /tmp/mysql.sock"
As each site has it’s own socket this command would need to be run in each site’s shell.
Is there any update on this?
I have the latest Local version and I still get “ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)” error.
I tried solutions found in this thread, but always end up with errors like this:
‘alias’ is not recognized as an internal or external command, operable program or batch file.
I still get the “Can’t connect to local MySQL server through socket” with the latest version of Local and even after trying the suggestion by @afragen . Manually specifying the socket with each command will work though.
Thanks for the follow-up!
This is was a bug with the DB subcommand in WP-CLI. A member of our team submitted a PR upstream that has since been merged. It’s on our list to get the fix implemented and make the necessary WP-CLI config adjustments to take advantage of it!
@richardbuff that command creates an alias to the actual command.
The command is as follows.
SOCKET=$(mysqld --verbose --help | grep ^socket | awk '{print $2, $3, $4}');ln -sfv $SOCKET /tmp/mysql.sock
@clay the PR was merged in Jan 2020. Not sure about when the next release of wp-cli incorporates it.



