At 14:01 -0600 3/10/03, Pete Harlan wrote:
>On Mon, Mar 10, 2003 at 11:32:06AM -0600, Paul DuBois wrote:
>> Whether it's a feature or not, it's not always so easy to figure out
>> what to do. If you specify -h localhost, it can be argued that you
>> really want the socket even if you specify the port. It can be
>> argued conversely that if you specify the port, you should use TCP/IP
>> even if you specify -h localhost.
>>
>> That is, if the user specifies both, it's ambiguous what the user really
>> wants.
>
>But "localhost" is a DNS name that only happens to resolve to
>127.0.0.1. MySQL breaks this DNS abstraction by treating "localhost"
>as a keyword, different from 127.0.0.1, which goes against the
>principle of least surprise. (It confused me, anyway.)
>
>I think it would have been less confusing to treat "localhost" the
>same as its resolved IP address, and decide whether to use a local
>socket vs. a port number on the basis of a different argument (-l for
>local, perhaps, which would be the default when connecting to
>127.0.0.1 (or localhost, or any other name that resolved to this IP)).
In 4.1, there will be a --protocol option that allows the connection
type to be specified. This will have the effect of allowing the user
to specify intent unambiguously.
>
>Wild speculation: The current design was chosen back when MySQL didn't
>have different sections in /etc/my.cnf, so the port specification for
>the server was also used for the client. In that case the client
>usually read a port specification (in /etc/my.cnf), but in the common
>case the client wouldn't obey it, which typically did the right
>thing. (Now that there are separate [client] and [server] sections in
>my.cnf things are less jumbled.)
That is indeed speculation, and it's incorrect. Option files were
introduced around 3.22.10, and they've always had sections.
>
>The client could be made to obey a command-line argument, while still
>silently ignoring the my.cnf argument. (That's what my patch did.)
>
>It's not just the mysql client, it's the client library, which is what
>bit us. You specify a port in the DBI->connect() routine as something
>like ';host=localhost;port=2000' and it's silently ignored there too.
Well, sure. Options just map onto arguments to the mysql_real_connect()
C library call, and the ambiguity of intent carries all the way down
to that level.
>
>I'm very glad that ssh no longer (as of three years ago!) forwards
>externally-connected-to ports by default.
>
>--Pete