Bug #55796 mysql cli-tool ignores port on localhost
Submitted: 6 Aug 2010 8:43 Modified: 6 Aug 2010 17:34
Reporter: Boa Thor Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.49 OS:Any
Assigned to: CPU Architecture:Any
Tags: CLI MYSQL Port Localhost

[6 Aug 2010 8:43] Boa Thor
Description:
I am using multiple MySQL instances on a single server. (For a reason).
It really sucks that I can not test the connection to my instances via localhost port. (Like my scripts are doing it.)

the mysql client SILENTLY!!! ignores the port-argument --port when no host is given or localhost is specified. This is totally unlogic and is not the behaviour that any one would expect.

Hope this is fixed in newer version.

How to repeat:
use mysql --port argument combined with -h localhost

Suggested fix:
make --port work on localhost,  there are people out there using different ports then 3306.
[6 Aug 2010 8:52] Boa Thor
Especially in combination with PHP your localhost connection will ALLWAYs be made to the wrong instance / the one listening to 3306.
[6 Aug 2010 8:57] Valeriy Kravchuk
I think our manual, http://dev.mysql.com/doc/refman/5.1/en/connecting.html, clearly explains this:

"On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P  option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option."
[6 Aug 2010 17:34] Boa Thor
Silently ignoring any user input is a bad habbit and no tool should ever do this.
[23 Jan 2015 15:21] David Bennett
This is misleading at the very least:

mysql -P ####

Should do one of:

a) Throw a warning stating TCP port is ignored in socket mode
b) Fail with an stating TCP port is ignored in socket mode
c) Assume TCP/IP mode

It's simply too easy to connect to the wrong service without knowing it.
[17 Jan 2018 13:49] Martin Häcker
So, are you going to change this?
[21 Jan 2019 2:49] John Lin
Is there any update on this bug? Why is it labeled as "Not a Bug"?
[25 Apr 2019 16:59] Jonathan Williams
Ignoring a command line parameter without warning is a bug.  The fact that it's clearly documented makes it a clearly documented bug.

Supplying a --port= or -P command line parameter when connecting to localhost on 'nix systems should fail.  If that's not acceptable, it should at least generate a warning:

$ mysql -P 3307 -p
mysql: [Warning] --port command line argument ignored when connecting via sockets.
Enter password:

I agree with others that have commented here.  This should be classified as a bug.