Bug #6246 mysql command line client uses socket connection when --host=localhost & --port
Submitted: 25 Oct 2004 16:06 Modified: 25 Oct 2004 17:31
Reporter: David Mohr Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:4.0.20 OS:Linux (Debian Linux)
Assigned to: CPU Architecture:Any

[25 Oct 2004 16:06] David Mohr
Description:
When using the command line parameters --host=localhost and --port, the mysql command line client assumes that it is a local socket connection even though a port is specified and I want to invoke it through a tcp connection. I encountered this problem when trying to connect to a ssh-forwarded mysql connection (thus using localhost and a different port number).
I'm not running a local mysql server but 'mysql' tries to connect to it through sockets, output:
---
ERROR 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
---

How to repeat:
mysql --host=localhost --port=13306

Suggested fix:
When you use --host=127.0.0.1 it works fine, so I assume that it is hardcoded somewhere that when host==localhost there has to be a socket connection. You could easily add a check that if --port is also specified, it has to be a tcp and not a socket connection.
[25 Oct 2004 17:31] MySQL Verification Team
This is expected behaviour, as per our manual.

Try --host=127.0.0.1
[7 Aug 2006 16:38] Kevin Benton
IMNSHO, this is a bad idea.  I would hope that the API would sense that the user specified a port number and if the socket didn't exist, attempt to connect via TCP/IP.  If both methods fail, then the API should return an error message.