Bug #20483 Unable to assign TCP port below 1024
Submitted: 15 Jun 2006 14:59 Modified: 25 Jan 2008 20:48
Reporter: Rick Gaither Email Updates:
Status: Unsupported Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.022 OS:Linux (Linux FD5)
Assigned to: CPU Architecture:Any
Triage: D4 (Minor)

[15 Jun 2006 14:59] Rick Gaither
Description:
The MySql Server fails on startup if the TCP port is set to less than 1024, unless the user is set to root. . This occurs for both standard startup (mysqld_safe) and MySql Manager (mysqld[n]). Extensive testing was conducted to narrow and define the issue.

Linux OS prevents direct “reserved port” assignments by any process other than system root (user id: 0). However, processes that run under non-systems accounts (like Apache) will assign the necessary IP ports and other security configurations before changing the user. MySql 4.1 (and below) did this okay. However this release apparently now sets the user before assigning the TCP port which causes the port assignment (and program) to fail.

How to repeat:
- MySql Version 5.0.22 - Attempt to startup the MySql server with any port number less than 1024 and user set to “mysql” (default). 

The startup will completely fail on standard start (mysqld_safe) and the MySql Manager will fail to start the individual server that has a port < 1024. The Manager itself starts normally

Setting the user to root will allow the process to start.

Suggested fix:
Update the code to reset the process user at the very last, after the TCP port and all other OS sensitive configurations have been completed.
[16 Jun 2006 18:49] Tonci Grgin
Hi Rick  and thanks for your problem report.
Verified as described by reporter on Suse 10.0, all latest BK builds
 - WORKS OK - 
060616 20:35:33  mysqld started
060616 20:35:33  InnoDB: Started; log sequence number 0 276349
/home/Tonci/bkwork/copyto/mysql-4-1/libexec/mysqld: ready for connections.
Version: '4.1.21-debug-log'  socket: '/var/lib/mysql/mysql.sock'  port: 1023  Source distribution
060616 20:35:43 [Note] Got signal 15 to shutdown mysqld
060616 20:35:43 [Note] /home/Tonci/bkwork/copyto/mysql-4-1/libexec/mysqld: Normal shutdown

060616 20:35:43  InnoDB: Starting shutdown...
060616 20:35:46  InnoDB: Shutdown completed; log sequence number 0 276349
060616 20:35:46 [Note] /home/Tonci/bkwork/copyto/mysql-4-1/libexec/mysqld: Shutdown complete

060616 20:35:46  mysqld ended

 - WORKS NOT (<1024) - 
- 5.0 BK -
060616 20:26:40  mysqld started
060616 20:26:40  InnoDB: Started; log sequence number 0 525314605
060616 20:26:40 [ERROR] Can't start server: Bind on TCP/IP port: Permission denied
060616 20:26:40 [ERROR] Do you already have another mysqld server running on port: 1023 ? and below
060616 20:26:40 [ERROR] Aborting

060616 20:26:40  InnoDB: Starting shutdown...
060616 20:26:42  InnoDB: Shutdown completed; log sequence number 0 525314605
060616 20:26:42 [Note] /home/Tonci/bkwork/copyto/mysql-5-0/libexec/mysqld: Shutdown complete

060616 20:26:42  mysqld ended

060616 20:26:44  mysqld started
060616 20:26:45  InnoDB: Started; log sequence number 0 525314605
060616 20:26:45 [Note] /home/Tonci/bkwork/copyto/mysql-5-0/libexec/mysqld: ready for connections.
Version: '5.0.23-debug'  socket: '/tmp/mysql.sock'  port: 1024  Source distribution
060616 20:28:08 [Note] Got signal 15 to shutdown mysqld
060616 20:28:08 [Note] /home/Tonci/bkwork/copyto/mysql-5-0/libexec/mysqld: Normal shutdown

060616 20:28:08  InnoDB: Starting shutdown...
060616 20:28:11  InnoDB: Shutdown completed; log sequence number 0 525314605
060616 20:28:11 [Note] /home/Tonci/bkwork/copyto/mysql-5-0/libexec/mysqld: Shutdown complete

060616 20:28:11  mysqld ended

 - 5.1 BK -
060616 20:30:42  mysqld started
060616 20:30:43  InnoDB: Started; log sequence number 0 278575248
060616 20:30:44 [ERROR] Can't start server: Bind on TCP/IP port: Permission denied
060616 20:30:44 [ERROR] Do you already have another mysqld server running on port: 1023 ? and below
060616 20:30:44 [ERROR] Aborting

060616 20:30:44  InnoDB: Starting shutdown...
060616 20:30:46  InnoDB: Shutdown completed; log sequence number 0 278575248
060616 20:30:46 [Note] /home/Tonci/bkwork/copyto/mysql-5-1/libexec/mysqld: Shutdown complete

060616 20:30:46  mysqld ended

060616 20:31:02  mysqld started
060616 20:31:03  InnoDB: Started; log sequence number 0 278575248
060616 20:31:03 [Note] /home/Tonci/bkwork/copyto/mysql-5-1/libexec/mysqld: ready for connections.
Version: '5.1.12-beta-debug'  socket: '/tmp/mysql.sock'  port: 1024  Source distribution
060616 20:31:03 [Note] SCHEDULER: Manager thread booting
060616 20:31:03 [Note] SCHEDULER: Loaded 0 events
060616 20:31:03 [Note] SCHEDULER: Suspending operations
060616 20:31:11 [Note] Got signal 15 to shutdown mysqld
060616 20:31:11 [Note] /home/Tonci/bkwork/copyto/mysql-5-1/libexec/mysqld: Normal shutdown

060616 20:31:11 [Note] SCHEDULER: Killing manager thread 1
060616 20:31:11 [Note] SCHEDULER: Waiting the manager thread to reply
060616 20:31:11 [Note] SCHEDULER: Resuming operations
060616 20:31:11 [Note] SCHEDULER: Manager thread started with id 1
060616 20:31:11 [Note] SCHEDULER: Shutting down
060616 20:31:11 [Note] SCHEDULER: Waiting for worker threads to finish
060616 20:31:11 [Note] SCHEDULER: Emptying the queue
060616 20:31:11 [Note] SCHEDULER: Stopped
060616 20:31:11  InnoDB: Starting shutdown...
060616 20:31:13  InnoDB: Shutdown completed; log sequence number 0 278575248
060616 20:31:13 [Note] /home/Tonci/bkwork/copyto/mysql-5-1/libexec/mysqld: Shutdown complete

060616 20:31:13  mysqld ended
[30 Dec 2007 23:14] Rick Gaither
Any particular reason this serious bug has gone unresolved and not even reviewed in over a year and a half?
[31 Dec 2007 8:38] Tonci Grgin
Hi Rick, we don't see this as a "bug" let alone serious one so I can't give you ETA on fixing it nor even the information on will it ever be fixed.

Thanks for your interest in MySQL.