Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL --no-defaults flag causes incorrect socket path #155

Closed
Muffinman opened this issue Nov 27, 2019 · 4 comments
Closed

MySQL --no-defaults flag causes incorrect socket path #155

Muffinman opened this issue Nov 27, 2019 · 4 comments
Milestone

Comments

@Muffinman
Copy link

Muffinman commented Nov 27, 2019

Bug Report

Describe the current, buggy behavior

On my macOS system, I have MySQL set up to listen at /usr/local/var/mysql/mysql.sock. I have this correctly configured in my php.ini and mysql server/client config files so that everything works as normal.

For some reason, the wp db command seems to have the --no-defaults flag so all mysql client settings are ignored. This causes all wp db commands to fail as it falls back to the old socket path at the time MySQL was compiled.

I'm wondering what the thought process was behind this flag? As far as I know the defaults can be easily overridden by specifying the flags, so I can't see what purpose this has. I found the commits where this was added, but no mention of why.

4fb8599
0bcaa75

Describe how other contributors can replicate this bug

  • Create custom MySQL socket path and make sure it is available and listening
  • Set this socket path in php.ini and mysql client config
  • Try wp db import or wp db export

Example

 ~> mysql 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 91809
Server version: 10.4.9-MariaDB Homebrew

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye
 ~> mysql --no-defaults
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Describe what you would expect as the correct outcome

The wp db command should correctly pick up the default socket path from the PHP ini or default MySQL client settings.

Let us know what environment you are running this on

OS:	Darwin 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64
Shell:	/usr/local/bin/fish
PHP binary:	/usr/local/bin/php
PHP version:	7.3.11
php.ini used:	/usr/local/etc/php/7.3/php.ini
WP-CLI root dir:	/Users/matt/.composer/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	/Users/matt/.composer/vendor
WP_CLI phar path:
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version:	2.4.0

Provide a possible solution

Remove --no-defaults from mysql commands, or attempt to fetch socket path from PHP / MySQL.

@schlessera
Copy link
Member

@Muffinman This will be fixed in the next release via #157 through the addition of a --defaults flag which counters the default --no-defaults behavior. This behavior is still the default, though, for backwards compatibility reasons.

@schlessera schlessera added this to the 2.0.6 milestone Jan 9, 2020
@janw-me
Copy link
Member

janw-me commented Aug 2, 2021

I'm also having this problem with other commands

  • wp db query "SHOW TABLES;"
  • wp db query "SHOW TABLES;" --defaults !Also gives an error
  • wp db reset --yes
  • wp db clean --yes
  • wp db drop --yes

Also see the localWP thread

@schlessera
Copy link
Member

@janw-me I assume this is a duplicate of #185. I started fixing it via #206 but was slowed down because I hit a bug in WP core (https://core.trac.wordpress.org/ticket/53830).

@janw-me
Copy link
Member

janw-me commented Aug 3, 2021

Ahh yes this is exactly the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants