Local Community

Unable to run Db Export via CLI

Hi all,

Just setup Local and for the most part i’m loving it. I am experiencing an issue when running wp db export though in shell.

I get the following error:

mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect

Also when attempting to connect using Sequel pro I get the following too.

I’m not sure what I’m missing here. I have checked the files in the screenshot and not having any luck on this.

1 Like

Howdy folks,

Curious if we’ve got any update on this. Loving LOCAL so far except for this one little issue
which is actually a big issue in a way.

1 Like

Hey @darraghb

I’m honestly not sure why that isn’t working, but as a workaround you can find the socket on the database tab in Local.

With that, you can add it to the export command if you are using WP CLI.

Something like this:

 wp db export db-backup.sql --socket="/Users/username/Library/Application Support/Local/run/Zz3-D-Hl-/mysqld.sock"

The socket path with be unique to each site.

5 Likes

Cool, that works! Yay! Is there any way of getting the SQL socket address programmatically? I’ve got 3 or 4 users on different platforms (Linux/Mac) and each has different .../run/??????/mysqld.sock – which means I can’t create a universal script for all the users.

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