Bug #31832 mysql executable ignores --protocol when $MYSQL_HOST is set
Submitted: 25 Oct 2007 6:52 Modified: 19 May 2009 1:21
Reporter: Paul Rivers (Candidate Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0.41, 5.0, 5.1 BK OS:Linux
Assigned to: CPU Architecture:Any
Tags: qc

[25 Oct 2007 6:52] Paul Rivers
Description:

When the environment variable MYSQL_HOST is set, mysql will fail to connect regardless, even when --protocol=socket.

How to repeat:

Setup a mysql 5.0.41 server to listen on both a UNIX socket and TCP.  Ensure the ID is allowed to connect on either.

Set the environment variables MYSQL_HOST and MYSQL_TCP_PORT to the appropriate values.  

Connect via mysql without specifying host or port.  It works as it should.

Now try mysql --protocol=socket --socket=/your/socket/file/here

The connection fails with:

ERROR 2047 (HY000): Wrong or unknown protocol

Now unset MYSQL_HOST only.  Repeat the connection attempt with the socket.  It is successful.

Suggested fix:

Do not prioritize MYSQL_HOST above --protocol.  --protocol should determine which other command-line or environment variables are required to connect.

If --protocol is unspecified, it's fine to default to tcp or whatever (so long as this is *documented* behavior).  

In fact, it would be ideal to add MYSQL_PROTOCOL (or something of the sort) as an environment variable, so the default could be set this way.
[25 Oct 2007 7:01] Paul Rivers
I'm sorry, it's late here, and I realize my description is poorly worded.  Please consider this the description instead:

When the environment variable MYSQL_HOST is set, the client utility mysql will fail to connect to the instance if a socket connection is asked for via --protocol=socket.
[25 Oct 2007 10:40] Sveta Smirnova
Thank you for the report.

Verified as described.
[19 May 2009 1:07] Jim Winstead
The problem here is that if MYSQL_HOST is anything other than 'localhost', it will fail because UNIX sockets can't be used to connect to any other host. A more useful error message should probably be returned.
[19 May 2009 1:21] Paul Rivers
Why would $MYSQL_HOST be confined to a UNIX socket file, and not for example obviate the need to specify -h to the mysql command line client?  This would seem more intuitive and useful.