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.
If you use the alias command globally you can then simply run local-socket
in the Site Shell.
It looks like it’s going out in WP-CLI 2.4.1 which includes db-command
2.0.6: Update mustache dependency and remove patch · wp-cli/wp-cli@ceb1859 · GitHub
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
still links to 2.4.0 but that shouldn’t be a deal-breaker for us.
Good to know a fix is come soon!
@afragen I still get an error when doing it like in the screenshot below. Am I still doing something wrong?
Well that’s at least a different error.
I assume this is in the Site Shell. If the socket path matches the symlink in the database tab.
Not sure I’ve got much else.
I was finally able to resolve a similar problem I was having with a solution on this post Unable to run Db Export via CLI
don’t know how i missed this earlier but the –socket argument after my wp cli db command totally works. There’s a screenshot on that post that explains it. Good luck!
FYI, I had to modify this command to not only escape the dollar-sign in $SOCKET
as you have done, but also wrap it in quotation marks because of the spaces in the path. Which is quite strange–I would expect you to have to do the same, but apparently not.
I have a different problem, though
When I create the local-socket
alias that you describe and then run it, things are good: I can run WP-CLI db commands without specifying the socket in the command. I would expect that I could save the alias in ~/.bash_profile
in order to have it available each time I launch the shell from Local. I have done this, but when I run local-socket
I get the error:
bash: local-socket: command not found
Did you do something so that you could save the alias and have it available between site restarts and closing/opening the shell?
@positivejam I’m really not aware that I did anything special to have the alias globally available. I may have created the alias outside of the site shell initially.
You would need to run the command every time you work in a new site shell as the socket would change and you must reference the correct database.
Not sure about the escaping but glad you got it working.
I’m not sure which OS you’re on but, you might double check to see if you have a ~/.bashrc file instead.
When you added the alias, did you also do source ~/.bash_profile
to update the shell? (edit, didn’t finish this sentence.)
I use zshell, so my file is .zshrc but, I was able to add an alias to my file. Opening a new site shell allowed me to use the alias. As long as the same terminal program is used for your site shell and reads the same .bash_profile, then you should have no issues setting up global alias.
That was it!
I’m on mac os. The reason I was so confused was that when I’d open Terminal, .bash_profile
would run, but despite adding my alias to .bash_profile
, the alias wouldn’t be set in Terminal windows popped by Local. And that was because Local is running .bashrc
.
Really, just needed to learn the differences between the two. Thanks folks!
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.