Bug #15327 configure: --with-tcp-port option being partially ignored
Submitted: 29 Nov 2005 20:23 Modified: 23 Oct 2007 0:11
Reporter: Paul Dubois Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.0/5.1 OS:Linux (linux)
Assigned to: Tatiana Azundris Nuernberg CPU Architecture:Any
Tags: bfsm_2007_07_19

[29 Nov 2005 20:23] Paul Dubois
Description:
Clients are ignoring the --with-tcp-port option. For mysql, this
began with 5.0.12. It seems to affect other clients beginning
with 5.0.17 (mysqladmin and mysqldump at least; I haven't
tried all clients).

How to repeat:
Build a 5.0.17 distribution with --with-tcp-port=50017
to compile in port 50017 to MySQL programs, and then
install the distribution and launch the server.

Invoke a just-built client with -h 127.0.0.1 to force a TCP/IP
connection and see which server it connects to.  I expect the client
to connect to the server that is listening on port 50017,
but instead I get my default server that is listening on port
3306.

Note: the value of MYSQL_PORT in mysql_version.h is
correct (50017).
[19 May 2006 12:22] Jiri Kaderavek
I confirm this bug in the case of mysql command line utility (don't tried another tools). Additionaly, you must specify --protocol-tcp option to mysql command utility to be able to connect to other localhost port then default. This bug is very confusing as it's possible, that you modify the data on inappropriate database server.
[19 May 2006 12:23] Jiri Kaderavek
Correction --protocol=tcp
[22 Sep 2006 15:05] Paul Dubois
Further information:

The bug affects the server as well, and for clients it is not just
cosmetic (that is, when clients display a port value 0 for --help
output, that's not just a display problem; clients really do use
3306, not the configured-in --with-tcp-port value).

You can demonstrate the problem as follows.

Suppose I configure MySQL 5.1.12 using --with-tcp-port=50112.  What I
expect to happen is this:

- mysqld should listen on port 50112 by default
- client programs should connect to the server using port 50112 by default.
- Instance Manager, if it starts a default ([mysqld]) server, should
  monitor that server by connecting to port 50112 by default.

None of that happens now, due to the problem described in Bug#15327.
What happens is that the server listens on 3306, clients connect to 3306,
and IM also thinks it should connect to the server on 3306.

If you run the server with no options, it listens on 3306, and the
clients connect to it using 3306.  If you explicitly configure with
server at runtime with --port=50112 to use the port that *should*
have been configured in, trying to connect with a client fails.
(Unless you happen to have another server listening on 3306; then
the 5.1.12 client connects to that server, which is not what should
happen.)

The bug also affects Instance Manager, which thinks the default 
port is 3306, not 50112.  Currentl, due to the bug, IM connects to
3306 by default, which is indeed what the server is listening to
by default.  But that's not what *should* happen.  Suppose you have 
a production server for some other version that uses 3306, and then
you configure a 5.1.12 distribution as described above to use for
testing.  The newly configured distribution should use 50112 by
default, but it uses 3306, causing a mess.

The bug just makes it more difficult than it should be to run
MySQL for lots of different versions simultaneously on the same
machine.  The basedir can be configured differently, and it is
respected.  The socket file can be configured differently, and
it is respect. The TCP/IP port number can be configured differently,
but it is NOT respected.

This used to work before 5.0.12.  Please make it work again.
The problem was already bad; it's becoming worse with recent
changes (in 5.1.12) that allow Instance Manager to start and
monitor a default instance: The server *and* Instance Manager
both use the wrong default server port now.

Changing category from Command-line clients to Server:
Compiling, because it's also a server problem.
[25 May 2007 15:38] Paul Dubois
I have changed the synopsis to note that the bug affects the server and not just clients.

Also, another observation: master-port and report-port do pick up the value of the --with-tcp-port option. It's only port that is affected, and does not use the correct value.
[8 Jul 2007 16:46] Mark Leith
Further checking shows that this is because mysqld is choosing to run on the port specified within /etc/services, rather than the port set within mysql_version.h. If I set the port number to 13306 within /etc/services:

[markleith@medusa:~/mysql/mysql-5.0-newport] $ 070708 17:24:17 [Warning] Setting lower_case_table_names=2 because file system for /Users/markleith/mysql/mysql-5.0-newport/var/ is case insensitive
070708 17:24:17 [Warning] No argument was provided to --log-bin, and --log-bin-index was not used; so replication may break when this MySQL server acts as a master and has his hostname changed!! Please use '--log-bin=/Users/markleith/mysql/mysql-5.0-newport/var/medusa-bin' to avoid this problem.
070708 17:24:17  InnoDB: Started; log sequence number 0 43655
070708 17:24:17 [Note] Recovering after a crash using /Users/markleith/mysql/mysql-5.0-newport/var/medusa-bin
070708 17:24:17 [Note] Starting crash recovery...
070708 17:24:17 [Note] Crash recovery finished.
070708 17:24:17 [Note] ./libexec/mysqld: ready for connections.
Version: '5.0.46-log'  socket: '/tmp/mysql.sock'  port: 13306  Source distribution

Within mysqld.cc:

static void set_ports()
{
  char  *env;
  if (!mysqld_port && !opt_disable_networking)
  {                                     // Get port if not from commandline
    struct  servent *serv_ptr;
    mysqld_port= MYSQL_PORT;
    if ((serv_ptr= getservbyname("mysql", "tcp")))
      mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
    if ((env = getenv("MYSQL_TCP_PORT")))
      mysqld_port= (uint) atoi(env);            /* purecov: inspected */
  }
  if (!mysqld_unix_port)
  {
#ifdef __WIN__
    mysqld_unix_port= (char*) MYSQL_NAMEDPIPE;
#else
    mysqld_unix_port= (char*) MYSQL_UNIX_ADDR;
#endif
    if ((env = getenv("MYSQL_UNIX_PORT")))
      mysqld_unix_port= env;                    /* purecov: inspected */
  }
}

This looks to me as if it is actually overriding the port within mysql_version.h, i.e that set here:

mysqld_port= MYSQL_PORT;

With the call to getservbyname().
[8 Aug 2007 15:31] 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/32255

ChangeSet@1.2476, 2007-08-08 17:34:55+02:00, tnurnberg@sin.intern.azundris.com +16 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
  
  initialize default tcp port for client and server, like so:
  - if user configured --with-tcp-port, use that value as default
  - other assume "use a good default": search mysqld/tcp in
    /etc/services; if that doesn't exist, use factory default (3306)
  - environment variable MYSQL_TCP_PORT overrides this default
  - command-line option overrides all of the above
[21 Aug 2007 18:13] 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/32827

ChangeSet@1.2476, 2007-08-21 20:17:34+02:00, tnurnberg@sin.intern.azundris.com +30 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
  
  make sure that if builder configured with a non-standard (!= 3306)
  default TCP port that value actually gets used throughout. if they
  didn't configure a value, assume "use a sensible default", which
  will be read from /etc/services or, failing that, from the factory
  default. That makes the order of preference
  - command-line option
  - my.cnf, where applicable
  - $MYSQL_TCP_PORT environment variable
  - /etc/services (unless configured --with-tcp-port)
  - default port (--with-tcp-port=... or factory default)
[13 Sep 2007 14:13] 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/34184

ChangeSet@1.2476, 2007-09-13 16:19:46+02:00, tnurnberg@mysql.com +26 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
  
  make sure that if builder configured with a non-standard (!= 3306)
  default TCP port that value actually gets used throughout. if they
  didn't configure a value, assume "use a sensible default", which
  will be read from /etc/services or, failing that, from the factory
  default. That makes the order of preference
  - command-line option
  - my.cnf, where applicable
  - $MYSQL_TCP_PORT environment variable
  - /etc/services (unless configured --with-tcp-port)
  - default port (--with-tcp-port=... or factory default)
[15 Sep 2007 2:54] 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/34309

ChangeSet@1.2578, 2007-09-15 04:59:46+02:00, tnurnberg@mysql.com +1 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
  
  after merge fix :-/
[17 Sep 2007 13:29] Timothy Smith
Queued to 5.0- and 5.1-maint
[21 Sep 2007 15: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/34458

ChangeSet@1.2477, 2007-09-21 11:38:23-04:00, iggy@alf.(none) +1 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
    
  make sure that if builder configured with a non-standard (!= 3306)
  default TCP port that value actually gets used throughout.
[21 Sep 2007 16:06] 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/34460

ChangeSet@1.2603, 2007-09-21 12:05:54-04:00, iggy@alf.(none) +1 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
      
  make sure that if builder configured with a non-standard (!= 3306)
  default TCP port that value actually gets used throughout.
[18 Oct 2007 21:34] Bugs System
Pushed into 5.1.23-beta
[18 Oct 2007 21:36] Bugs System
Pushed into 5.0.52
[23 Oct 2007 0:11] Paul Dubois
Noted in 5.0.52, 5.1.23 changelogs.

Clients were ignoring the TCP/IP port number specified as the
default port via the --with-tcp-port configuration option.