Bug #64703 Providing socket as an option does not override host and port in my.cnf
Submitted: 20 Mar 2012 11:31 Modified: 20 Mar 2012 12:04
Reporter: Alex Bolenok Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.61 OS:Linux
Assigned to: CPU Architecture:Any
Tags: command line options, my.cnf

[20 Mar 2012 11:31] Alex Bolenok
Description:
I have a remote server set in .my.cnf:

host = myhost.example.com
password = "mypassword"

When I try to connect to the local server through the socket:

mysql -S /tmp/mysql.sock

it silently connects to the default remote server.

To override this, one should provide the -h option as well:

mysql -h localhost -S /tmp/mysql.local.sock

How to repeat:
Create a ~/.my.cnf file with the following contents:

[mysql]
host = myhost.example.com
password = "mypassword"

Start a local MySQL instance listening on /tmp/mysql.sock

Run:

mysql -S /tmp/mysql.sock

Suggested fix:
Make --socket provided in configuration files or in a command option undefine --host setup in configuration files or lower priority.
[20 Mar 2012 12:01] Valeriy Kravchuk
Manual (http://dev.mysql.com/doc/refman/5.5/en/connecting.html) clearly says:

"Connections to remote servers always use TCP/IP."

Only connections to localhost on Linux uses socket by default. So, as soon as host value is defined and it is not localhost, it is expected that TCP/IP is used.

IMHO we have a feature request here, for a new behavior in case socket is explicitly specified.
[20 Mar 2012 12:04] Alex Bolenok
Actually, I would expect mysql -S /path/to/socket to connect to the socket, no matter what the config files say. I think it should be a bug.
[20 Mar 2012 14:23] Georgi Kodinov
While I agree with you that the fact that "mysql -S /path/to/socket" doesn't connect using a socket looks odd let me explain why it is designed this way.
We the developers are trying hard to avoid interdependent options. It would be confusing to have setting one option affecting the value of another.
And in mysql terms host, port, socket and pipe are different options.

So what you're asking for is having --socket affecting --host's value. 
It would have been different if mysql had e.g. a connect-url option that specifies a way to connect to the server instead of these individual options. Then what you expect would have been the natural way to implement it.

MySQL of  course has precendents already of options affecting another options : e.g. setting the --ssl-key changes the value of the --ssl option.
So your feature request is a valid one even in this setting.