wp-cli / db-command

Performs basic database operations using credentials stored in wp-config.php.
MIT License
71 stars 59 forks source link

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

Closed Muffinman closed 4 years ago

Muffinman commented 5 years ago

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.

https://github.com/wp-cli/db-command/commit/4fb859972901bef44a03c491316fa721b65b624e https://github.com/wp-cli/db-command/commit/0bcaa756c60e55dc04ff42e09461ad3540325952

Describe how other contributors can replicate this bug

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 commented 4 years ago

@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.

janw-me commented 3 years ago

I'm also having this problem with other commands

Also see the localWP thread

schlessera commented 3 years ago

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

janw-me commented 3 years ago

Ahh yes this is exactly the same.