Bug #16855 Command line options are ignored for mysql client
Submitted: 27 Jan 2006 21:21 Modified: 29 Jun 2006 21:05
Reporter: Jonathan Miller Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.6-alpha OS:Linux (Linux)
Assigned to: Ian Greenhoe CPU Architecture:Any

[27 Jan 2006 21:21] Jonathan Miller
Description:
Using this my.cnf
[manager]
default-mysqld-path = /home/ndbdev/jmiller/builds/libexec/mysqld
socket=/tmp/manager.sock
pid-file=/tmp/manager.pid
monitoring-interval = 50
port = 1999

[mysqld]
log        = /space/var/ndb18.log
log-error  = /space/var/ndb18.err
socket     = /tmp/mysql.sock
port       = 3306
pid-file   = /space/var/hostname.pid1
datadir    = /space/var/
language   = /home/ndbdev/jmiller/builds/share/mysql/english/
ndbcluster                      # run NDB engine
ndb-connectstring=ndb08:14000  # location of MGM node

[mysqld2]
log        = /space/var1/ndb18.log
log-error  = /space/var1/ndb18.err
socket     = /tmp/mysql2.sock
port       = 3307
pid-file   = /space/var1/hostname.pid1
datadir    = /space/var1/
language   = /home/ndbdev/jmiller/builds/share/mysql/english/
ndbcluster                      # run NDB engine
ndb-connectstring=ndb08:14000  # location of MGM node

I start the instances using the mysqlmanager. I then connect to mysqld running on port 3306 and create a database.

CREATE DATABASE xyz;

Then I log out and log into mysqld running on 3307.

CREATE DATABASE xyz;

and get : ERROR 1007 (HY000): Can't create database 'xyz'; database exists

if you look in the /space var directory you will see the xyz.frm but not in the var1 directory. But if I connect using socket, then the database is created and placed into the /space/var1 directory.

How to repeat:
see above
[27 Jan 2006 21:25] Jonathan Miller
[ndbdev@ndb18 tmp]$ mysql -u root --port=3307
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 5.1.6-alpha-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables;
+-------------------------------------+---------------------------------------------------+
| Variable_name                       | Value                                             |
+-------------------------------------+---------------------------------------------------+
| basedir                             | /home/ndbdev/jmiller/builds/                      |
| character_sets_dir                  | /home/ndbdev/jmiller/builds/share/mysql/charsets/ |
| datadir                             | /space/var/                                       |
| language                            | /home/ndbdev/jmiller/builds/share/mysql/english/  |
| pid_file                            | /space/var/hostname.pid1                          |
| port                                | 3306                                              |
| plugin_dir                          | /home/ndbdev/jmiller/builds/lib/mysql             |
| socket                              | /tmp/mysql.sock                                   |
---+---------------------------------------------------+
239 rows in set (0.00 sec)

Cut down to fit
[27 Jan 2006 23:37] Omer Barnir
To clarify the issue, the problem is that when using the 'mysql' client with a port option (but not specifying --protocol) i.e. mysql --port=9307 the client still defaults to a socket connection and if a socket file exists in the default location, connects using itso the users think they connect to one instance using the --port but in effect they connect to another instance using socket.

This is very confusing. The client needs to either
 - give a warning when a command line option is ignored
 - document clearly that --prootocol is required
 - prevent the client from defaulting to socket
[27 Jan 2006 23:39] Omer Barnir
Changing Title 
from: IM: MySQLD instance act differently then configured when connecting by ports
to: Command line options are ignored for mysql client
[27 Jan 2006 23:39] Omer Barnir
This behavior is observed on 5.0 client as well
[27 Jan 2006 23:54] Jonathan Miller
update
[23 Mar 2006 0:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/4040
[28 Mar 2006 1:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/4214
[28 Mar 2006 2:23] Ian Greenhoe
Fixed in 5.0 bk (patch #4124)

Fixed so that --port= causes a default of --protocol=TCP to be assumed unless --socket= is also seen.
[11 Apr 2006 2:00] Paul DuBois
We need the three-part version number for the push
so that we know which section the changelog entry
goes into.

By the way, this behavior discussed in this bug report
is common to all client programs, isn't it? Why fix it in
just the mysql client and not all clients?  Changing mysql
introduces an inconsistency between its behavior and
that of other clients.  So perhaps it eliminates one surprise
for users, but at the price of surprising them in the future
by having different clients behave differently with the same
options.
[12 Apr 2006 18:47] Chad MILLER
"""host=SomethingOtherThanLocalhost""" /does/ imply a socket type (packet family) and requires a port, but I don't expect """host=localhost""" to imply anything at all about socket type or port number.  

How should one connect to port N of this same machine, if one didn't want to use the named socket?
[12 Apr 2006 19:20] Sergei Golubchik
host=127.0.0.1 specifies tcp/ip, host=localhost specifies unix socket.
That's how MySQL behaved in the last 8 years at least (probably always).
So it is not a bug, but an intentional, well known, documented in every
MySQL book behaviour.
[12 Apr 2006 19:49] Ian Greenhoe
In the absense of other clues about the user's intent, that is an OK distinction to make.  However, when the user has specified a port (thru the --port option) and not specified a protocol or socket, then the user's intent becomes fairly clear:  connect to this port on this host.

Keep in mind that a lot of people want to use something without having to read all of the documentation.  Sometimes people forget.  Sometimes people don't have the time to remember or look it up.  Every other product that I have worked with assumes that if you only specify a port (and not a protocol or a socket), the program will connect to that port.
[18 Apr 2006 2:48] Ian Greenhoe
This should appear in 5.0.21.
[18 Apr 2006 7:31] Michael Widenius
This patch will not be put into MySQL as it breaks the intentend and documented behaviour of the MySQL clients.

The idea is that you can in your configuration files and on your command line use any protocol related option and this has no effect on the protocol your client is using.
Instead the protocol is defined by the --protocol option.

This enables you to have proper defaults in your configuration file, and you only have to specify --protocol=tcp or --protocol=socket on the command line to use the right port.

The proposed patch will seam to work in some cases and not in others, depending on what you have in your configuration files, and is thus worse than the current behaviour.
[18 Apr 2006 7:44] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/5050
[18 Apr 2006 8:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/5059
[18 Apr 2006 10:26] Jonathan Miller
How does that take into account multiple MySQLD's running on one Host?
[18 Apr 2006 17:28] Omer Barnir
Part of the problem with this bug is the confusing fact that you think you log in one way vs. another and one of the proposed fixes was to clearly document the behavior and/or warn about the fact that a command line option is ignored. It was not suggested to change thhe logic of the current behavior.
As such I'm not clear how it can be defied 'as not a bug'
Setting back to documenting since it doesn't seem there documetation was clarified
[18 Apr 2006 18:13] Ian Greenhoe
I'm pulling this out of documentation since there is not a consensus of how to proceed.

What I've heard so far indicates fear of breaking existing scripts if this behaviour changes.  In that case, my thinking is that the behaviour should remain the same, and we should print out a clear warning when we ignore the information.
[18 Apr 2006 18:22] Jonathan Miller
The biggest issue here is that I say connect to database on --port=3307 and instead under the covers I am connected to the one on 3306 because it went under the covers and found a mysql.sock file that it liked better. I am adding tables and doing all this stuff and find out after hours of work that I am on the wrong  database. 

Bad MySQL
[18 Apr 2006 18:40] Sergei Golubchik
You misunderstood what Monty has written.
A user may have 

[client]
port=3307

in my.cnf. And she will not appreciate if MySQL will suddenly start printing warnings about it.
[18 Apr 2006 20:07] Paul DuBois
To addresss the issue on the documentation front, I'll attempt
to clarify the behavior as follows in this section:

http://dev.mysql.com/doc/refman/5.0/en/invoking-programs.html

Currently, that has the first of the following paragraphs. I'll add the
second and third:

   Some options are common to a number of programs. The most common
   of these are the --host (or -h), --user (or -u), and --password
   (or -p) options that specify connection parameters. They indicate
   the host where the MySQL server is running, and the username and
   password of your MySQL account. All MySQL client programs
   understand these options; they allow you to specify which server
   to connect to and the account to use on that server.

   Other connection options are --port (or -P) to specify a TCP/IP
   port number, --socket (or -S) to specify a Unix socket file on
   Unix (or named pipe name on Windows).

   The default hostname is localhost. For client programs on Unix,
   the hostname localhost is special. It causes the client to connect
   to the MySQL server through 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 hostname 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.
[18 Apr 2006 20:21] Ian Greenhoe
Regarding the mysql.conf should not generate a warning:  This warning is needed in the case of a command line parameter being ignored.