Local Community

Unable to run Db Export via CLI

Hey Jake

thats brilliant.

Thanks so much for that help. Loving Local too.

This seems like a bug. the workaround above works, but it should use the socket automatically. @clay and team, is there something I’m missing here? I am on the 5.1 beta and got that error.

Thanks for the workaround @jkiley!

1 Like

Thank you so much this worked perfectly.

this helped me a lot. thank you! i haven’t been able to use the site shell to do wp cli stuff on the local database ever since i upgraded to Lightning. it’s not ideal but it definitely works using the --socket argument

This still seems to be an issue on version 5.6.6 of Local. To me, the proper fix seems to be to set the MYSQL_UNIX_PORT environment variable together with the other ones that get set when a site shell is opened.

Hey @gabkdlly and all –

This issue should be fixed with the most recent release of Local, 5.6.8:

Can you try installing the latest version and verify that everything is working on your end?

Yes, I can confirm that this seems to be fixed in 5.6.8, thanks!

1 Like

Nope, problem still persist on my Mac.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

MacOS 10.15.6
Local 5.6.8+4514

Interesting @jpozivil – It looks like you’re on Catalina like me. Couple of other questions:

  • What terminal program are you using?
  • What shell (bash, zsh, etc) are you using?
  • Do you have wpcli installed within your regular $PATH?
  • Can you take a screenshot of your terminal when you encounter this issue?

I’m on Catalina, using iTerm with zshell as my terminal. I don’t have wpcli installed other than what comes with Local and it’s not in my regular $PATH.

which wp on the shell session started from the local returns /Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/posix/wp

Thanks for that info!

All of that sounds similar to what I have. Here’s what my terminal startup looks like:

Looking at your screenshot, the main differences I see are:

  1. Different oh-my-zsh theme
  2. Different shell path (mine is /bin/zsh, yours is /usr/local/bin/zsh)
  3. Different “Last login” tty
  4. My prompt shows a red number which is the exit code of the last command. (the [1] in my screenshot) I wonder if there’s a bug that my terminal is just passing over, while your terminal isn’t working.

Maybe there’s something going on with how zsh is configured too. Do you have your dotfiles somewhere public that I can take a look at?

Here’s a screenshot of what I have for zsh config:

As well as a link to my dotfiles in case you want to take a look (though typical disclaimer, I need to cleanup the zsh starttime as well as all the things that are piled onto my $PATH)

Given all of that, can you answer a few questions?

  • Since the big thing that stands out to me is that the zsh binary is in a different location – can you tell me how you originally installed zsh?

  • Testing to see if you are getting a non-zero exit code, can you enter this in the terminal and let me know how it goes:

    echo $?

  • Also can you test manually running that site’s script from a running terminal? So looking at your screenshot, open a new terminal and run:

    ~/Library/Application Support/Local/ssh-entry/1ULnAY_XV.sh
    

Leaving this here – I tried also switching to the basic Bash shell

chsh -s /bin/bash

and then open a shell from Local. I didn’t get a non-zero exit code.

That may all be a red herring, since my ZSH instance is still able to work, but maybe it helps zero in on something happening on your end.

Here’s my .zshrc screenshot. Nothing too unusual, I’d say.

The theme I use displays a red :x: at the beginning of the prompt for a non-zero error codes. So, I’m don’t think, I’m getting any error 1 there.

To answer your questions.

  • Since the big thing that stands out to me is that the zsh binary is in a different location – can you tell me how you originally installed zsh?
    I can’t really remember but I believe I used brew
  • echo $? results in 0
  • Running the script from a new terminal results in no error:
$ ~/Library/Application\ Support/Local/ssh-entry/1ULnAY_XV.sh
-n -e
Setting Local environment variables...
----
WP-CLI:   WP-CLI 2.5.0-alpha
Composer: 1.10.8 2020-06-24
PHP:      7.3.5
MySQL:    mysql  Ver 8.0.16 for macos10.14 on x86_64 (MySQL Community Server - GPL)
----
Launching shell: /usr/local/bin/zsh ...

I’ve had a colleague with a Mac, but a different set up, to try it out too; and it does not work either.

Do you and your colleague have MySQL installed manually on the computer outside of Local? For example, installed using something like brew?

Funnily enough, if I try to run mysql, I get the same error message. I don’t recall installing MySQL. I’ve got a feeling that MacOS comes with MySQL preinstalled, but it’s not running by default.

I’ll try to follow this https://stackoverflow.com/a/21422630/1337386

Nice @jpozivil! I think that’s getting closer to the underlying issue!

For context, under the hood, Local is adjusting the $PATH and putting the various services (PHP, MySQL, NGINX/Apache) ahead of other things.

For my terminal, you can see that when opened through “Open Site Shell” the terminal session is using Local’s version of those binaries:

Given that your terminal is showing mysql as running from /usr/local/mysql/bin/mysql – I’m not sure that the linked StackOverflow answer would fix things in this case, since that answer would be starting the Host’s MySQL daemon, and not the MySQL daemon provided by Local.

What I think is happening is that Local’s MySQL binary isn’t being correctly added to your $PATH, or possibly something else (probably brew?) is adjusting the $PATH after Local has done so.

Can you try this and let me know what happens?

  1. Click “Open Site Shell”
  2. Echo the $PATH variable
  3. Leaving the current terminal open, edit the startup script. Comment out the last line of exec $SHELL
  4. source that shell script
  5. Echo the $PATH again, and try interacting with the db

I realize that’s probably a little confusing so hopefully this screenshot helps clarify:

I’ve tried after sourcing the modified start up script. Strange, I still get the same error.

When you echo the $PATH variable, do you see Local’s mysql binary in the path?

One other thing to note is that the startup script has two other bash variables that it is setting: $MYSQL_HOME and $WP_CLI_CONFIG_PATH

I notice that you are using the wp-cli “Oh my zsh” plugin – can you try temporarily commenting that out within the .zshrc file and see if that helps at all?

I do see the path for Local’s mysql /Applications/Local.app/Contents/Resources/extraResources/lightning-services/mysql-8.0.16+5/bin/darwin/bin, but then it gets over written by /usr/local/mysql/bin. Not quite sure how does that happen as in my .zshrc I’ve got PATH=export PATH=/usr/local/sbin:/usr/local/bin:$HOME/bin:$PATH. Surely that should add any existing string in the $PATH variable to the end.

export PATH=/usr/local/sbin:/usr/local/bin:$HOME/bin:$PATH /Users/jpozivil/Library/Application Support/Local/run/1ULnAY_XV/conf/mysql

Is it not a problem that the Application Support folder does not have the space character escaped?

$WP_CLI_CONFIG_PATH=/Applications/Local.app/Contents/Resources/extraResources/bin/wp-cli/config.yaml

It seems to make no difference whether I have the wp-cli “Oh my zsh” plugin in .zshrc or not.