welaika / wordmove

Multi-stage command line deploy/mirroring and task runner for Wordpress
https://wptools.it/wordmove
MIT License
1.87k stars 167 forks source link

Ongoing issues with error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' #426

Closed nailbrain closed 6 years ago

nailbrain commented 6 years ago

Hi,

I've had ongoing issues with the 2002 error.

I've gone through two threads that look like they we resolved but still can't fix the problem.

I hope you can help me.

After hunting around for my my.cnf file I found it in '/usr/local/opt/mysql/my.cnf'

Looks like I installed mySQL via home brew.

I changed the file to the following:

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = /Applications/MAMP/tmp/mysql/mysql.sock

I also tried changing it to:

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = /tmp/mysql.sock

When I ran 'sudo lsof | grep mysql.sock' it listed both '/Applications/MAMP/tmp/mysql/mysql.sock' and '/tmp/mysql.sock'.

I closed each one down independantly so only one was running and tested the above changes in my my.cnf file.

I then copied the my.cnf file to /etc/my.cnf and the the same as the above but with no luck.

Here is a copy of my wordmove file:

local:
  vhost: "http://localhost:8888/brett-dev-rebuild/"
  wordpress_path: "/Users/brettgolding/Google Drive/htdocs/brett-dev-rebuild" # use an absolute path here

  database:
    name: "brettdevrebuild"
    user: "root"
    password: "root"
    host: "localhost"

And here is a copy of the terminal error:

local | mysqldump --host=localhost --user=root --password=root --result-file="/Users/brettgolding/Google Drive/htdocs/brett-dev-rebuild/wp-content/dump.sql" brettdevrebuild
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect
/Users/brettgolding/.rvm/gems/ruby-2.4.2/gems/wordmove-2.1.3/lib/wordmove/deployer/base.rb:141:in `run': Return code reports an error (Wordmove::ShellCommandError)

I'm not quite sure if these settings are correct or what I am doing wrong.

alessandro-fazzi commented 6 years ago

Hello there!

First try: change localhost to 127.0.0.1 if you are on a Mac Second try: use mysql_adapter: 'wpcli' as per new documentation. If your own wordpress can connect to the database, that adapter will success too! Keep in minf wp-cli is a required peer dependancy for this adapter ;)

Hope you'll succeed.

Let me know

nailbrain commented 6 years ago

Thanks @pioneerskies for the quick reply.

I'm still getting the exact same error. I changed local host to 127.0.0.1.

I installed WPCLI using the following guide.

And changed the mysql_adapter.

global:
  sql_adapter: "wpcli"

local:
  vhost: "127.0.0.1"
  wordpress_path: "/Users/brettgolding/Google Drive/htdocs/brett-dev-rebuild" # use an absolute path here

  database:
    name: "brettdevrebuild"
    user: "root"
    password: "root"
    host: "localhost"

Here are the results of wp --info

BrettMac:etc brettgolding$ wp --info
PHP binary: /usr/bin/php
PHP version:    5.6.30
php.ini used:   
WP-CLI root dir:    phar://wp-cli.phar
WP-CLI vendor dir:  phar://wp-cli.phar/vendor
WP_CLI phar path:   /private/etc
WP-CLI packages dir:    
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 1.4.1
alessandro-fazzi commented 6 years ago

@nailbrain I remembered this old ticket while replying to you on a newer one.

wordmove doctor will also check if wordmove will be able to connect to the local database. If it won't be able, it means that mysqldump command can't access to the database. But this problem should be solved probably outside of the wordmove scope:

mysqldump --host=127.0.0.1 --user=root --password=root --result-file="/Users/brettgolding/Google Drive/htdocs/brett-dev-rebuild/wp-content/dump.sql" brettdevrebuild

should have to work on its own behalf.

alessandro-fazzi commented 6 years ago

Holy cow! @nailbrain I've re-read your issue and spotted out a thing: you have MAMP and you have also installed mysql via brew? This can cause problem with commands in $PATH. Let me know if you mind.

nailbrain commented 6 years ago

Hi @pioneerskies I've tried running wordmove doctor but got the error Could not find command "doctor".

Do you think it could be related to having multiple instances of mySQL installed?

I'm assuming I should uninstall mySQL using brew? Does Wordmove work well with MAMP?

alessandro-fazzi commented 6 years ago

@nailbrain I think it's only related to an outdated version of the gem 😂 🙈

alessandro-fazzi commented 6 years ago

Just saying: Wordmove merely ignore how you have installed MySQL. It just want to know how to connect to a server instance just like any other client, so don't worry ;)

alessandro-fazzi commented 6 years ago

Let's resume; I got a bit confused in some previous posts...my bad.

when I asked you

First try: change localhost to 127.0.0.1 if you are on a Mac

you actually changed the local.vhost, not local.database.host

global:
  sql_adapter: "wpcli"

local:
  vhost: "127.0.0.1"
  wordpress_path: "/Users/brettgolding/Google Drive/htdocs/brett-dev-rebuild" # use an absolute path here

  database:
    name: "brettdevrebuild"
    user: "root"
    password: "root"
    host: "localhost"

I meant

database:
    name: "brettdevrebuild"
    user: "root"
    password: "root"
    host: "127.0.0.1"

This can't return the same error, because you force mysqldump to connect via TCP leaving the socket connection away. This is not how Wordmove works, but just how mysql and mysqldump work.


Do you think it could be related to having multiple instances of mySQL installed?

So: wordmove doctor is not related: you just have an old wordmove version. I hope you upgraded to the latest since I can help supporting only on the latest (non beta) version.

Your problem with MySQL could be related to having multimple MySQL instances installed. But it is not a problem brought by Wordmove it's just a little mess on the development system ;) Requesting a TCP connection to 127.0.0.1 could bypass some of this confusion.

Where the confusion could be? When using localhost as DB host, mysqldump will search for a socket. Where the socket is is configured by default to /i/dont/know/where. Having multiple MySQL installed? Ok: both will have their command line tool. Using brew's mysqldump will use its own defaults, using MAMP's mysqldump will use its own defaults.

So: which mysqldump is wordmove calling? You should know that with

which mysqldump
which mysql

and you have to consider that the precedence between brew's commands and MAMP's commands is controlled by you shell's $PATH. If you start MAMP's MySQL server and then use brew's mysqldump it could work even if they are from different versions, but not if they are searching for different sockets


I hope to have re-ordered ideas a bit and I hope you'll have the time and the scenario to test these assumptions. If it is no more the case, I'd be glad if you'll close the issue just to keep things clean ;)

Cheers

nailbrain commented 6 years ago

Hi @pioneerskies I updated Wordmove and change the local DB host to 127.0.0.1.

I am now receiving the following error 'Got error: 2003: Can't connect to MySQL server on '127.0.0.1' (61) when trying to connect'.

It looks like this has been spoken about here but I couldn't find any clear resolution.

When I run which mysqldump I get back /usr/local/bin/mysqldump

And when I run which mysql I get back /usr/local/bin/mysql

When I run Wordmove doctor I get the following error message:

            ▬▬ Checking local database commands and connection                 ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
            ✓ success | `mysql` command is in $PATH
            ✓ success | `mysqldump` command is in $PATH
            ✗ error |   We can't connect to the MySQL server using credentials
            specified in the Movefile. Double check them or try
            to debug your system configuration.

            The command used to test was:

            mysql --host=127.0.0.1 --user=root --password=root -e'QUIT'
            ✗ error |   We can't connect to the database using credentials
            specified in the Movefile, or the database does not
            exists. Double check them or try to debug your
            system configuration.

            The command used to test was:

            mysql --host=127.0.0.1 --user=root --password=root valueinspiration -e'QUIT'

The credentials in my Wordmove file match my wp-config file DB credentials exactly, they are correct and the DB exists, of course, otherwise, I would of course not be able to work on this site locally.

nailbrain commented 6 years ago

@pioneerskies I've resolved the issue and got it working by adding port: "8889 to my local DB config. This is the port MAMP is configured on.

My config file now looks like this:

  database:
    name: "brettdevrebuild"
    user: "root"
    password: "root"
    host: "127.0.0.1"
    port: "8889" # Use just in case you have exotic server config
alessandro-fazzi commented 6 years ago

Keep in mind that you are using mysql and mysqldump executables from system installed MySQL to connect to your MAMP's MySQL server. As I said before this could work, but I'd not assure that in all situations: versions could be a lot different.

I would be in error if you have symlink-ed MAPS's binaries to /usr/local/bin or if MAPS's installation changed.

Anyway I'm happy it was just a custom port number problem.

I think we can close the ticket now.

Cheers