Can't start server: Bind on TCP/IP port: Permission denied

created at 12-13-2021 views: 54

background

The business installed a version of mysql server 5.7.25 of the percona branch by itself, and the port number was configured as 3307. Later, the business found that his computer and the machine had a firewall restriction, and wanted to bypass port 443 or 80 Over the firewall restrictions, the port number in the configuration file is changed to 443, as follows:

The startup command is as follows:

shell> /home/work/mysql_3307/bin/mysqld_safe --defaults-file=/home/work/mysql_3307/etc/my.cnf &

The content of the my.cnf file is as follows:

[client]
port = 443
socket = /home/work/mysql_3307/tmp/mysql.sock

[mysqld]# The problem appears in the following line of configuration. When the privileged port is less than 1024, root access is required, and the business wants to bypass the firewall restriction through port 443, user = work
port = 443
socket = /home/work/mysql_3307/tmp/mysql.sock
datadir = /home/work/mysql_3307/data
basedir = /home/work/mysql_3307
pid_file = /home/work/mysql_3307/tmp/mysql.pid
log-error = /home/work/mysql_3307/log/mysql.err
default-time-zone                                               = "+08:00"
thread_handling                                                 = pool-of-threads
thread_pool_stall_limit                                         = 50
thread_pool_oversubscribe                                       = 20
performance_schema                                              = 1
log_slave_updates
log_timestamps                                                  = SYSTEM
general_log = /home/work/mysql_3307/log/mysql.log
general_log = /home/work/mysql_3307/log/mysql.log
log_warnings
slow_query_log
slow_query_log_file = /home/work/mysql_3307/log/slow.log
tmpdir = /home/work/mysql_3307/tmp

View the mysql error log:

shell> less /home/work/mysql_3307/log/mysql.err

2021-09-10T11:59:39.494044+08:00 0 [Warning] option 'general_log': boolean value '/home/work/mysql_3307/log/mysql.log' wasn't recognized. Set to OFF.
2021-09-10T11:59:39.494128+08:00 0 [Warning] option 'general_log': boolean value '/home/work/mysql_3307/log/mysql.log' wasn't recognized. Set to OFF.
2021-09-10T11:59:39.494142+08:00 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead.
2021-09-10T11:59:39.494526+08:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-10T11:59:39.494572+08:00 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2021-09-10T11:59:39.494612+08:00 0 [Note] /home/work/mysql_3307/bin/mysqld (mysqld 5.7.25-28-log) starting as process 167258 ...
2021-09-10T11:59:39.503292+08:00 0 [Warning] option 'innodb-buffer-pool-chunk-size': unsigned value 128 adjusted to 1048576
2021-09-10T11:59:39.504031+08:00 0 [Note] InnoDB: PUNCH HOLE support available
2021-09-10T11:59:39.504054+08:00 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-09-10T11:59:39.504063+08:00 0 [Note] InnoDB: Uses event mutexes
2021-09-10T11:59:39.504071+08:00 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-09-10T11:59:39.504082+08:00 0 [Note] InnoDB: Compressed tables use zlib 1.2.7
2021-09-10T11:59:39.507458+08:00 0 [Note] InnoDB: Number of pools: 1
2021-09-10T11:59:39.507618+08:00 0 [Note] InnoDB: Using CPU crc32 instructions
2021-09-10T11:59:39.510419+08:00 0 [Note] InnoDB: Initializing buffer pool, total size = 10G, instances = 8, chunk size = 1M
2021-09-10T11:59:39.991718+08:00 0 [Note] InnoDB: Completed initialization of buffer pool
2021-09-10T11:59:40.063282+08:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-09-10T11:59:40.075849+08:00 0 [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /home/work/mysql_3307/data/xb_doublewrite
2021-09-10T11:59:40.077084+08:00 0 [Note] InnoDB: Opened 3 undo tablespaces
2021-09-10T11:59:40.077104+08:00 0 [Note] InnoDB: 3 undo tablespaces made active
2021-09-10T11:59:40.077505+08:00 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-09-10T11:59:40.148881+08:00 0 [Note] InnoDB: Created parallel doublewrite buffer at /home/work/mysql_3307/data/xb_doublewrite, size 31457280 bytes
2021-09-10T11:59:40.320501+08:00 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-09-10T11:59:40.320607+08:00 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-09-10T11:59:40.326149+08:00 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-09-10T11:59:40.327480+08:00 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-09-10T11:59:40.327496+08:00 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-09-10T11:59:40.327981+08:00 0 [Note] InnoDB: Waiting for purge to start
2021-09-10T11:59:40.378141+08:00 0 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.25-28 started; log sequence number 2504477
2021-09-10T11:59:40.378254+08:00 0 [Note] InnoDB: Loading buffer pool(s) from /home/work/mysql_3307/data/ib_buffer_pool
2021-09-10T11:59:40.378487+08:00 0 [Note] Plugin 'FEDERATED' is disabled.
2021-09-10T11:59:40.410408+08:00 0 [Note] InnoDB: Buffer pool(s) load completed at 210910 11:59:40
2021-09-10T11:59:40.410792+08:00 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2021-09-10T11:59:40.410817+08:00 0 [Note] Server hostname (bind-address): '*'; port: 443
2021-09-10T11:59:40.410869+08:00 0 [Note] IPv6 is available.
2021-09-10T11:59:40.410888+08:00 0 [Note]   - '::' resolves to '::';
2021-09-10T11:59:40.410906+08:00 0 [Note] Server socket created on IP: '::'.
2021-09-10T11:59:40.410944+08:00 0 [ERROR] Can't start server: Bind on TCP/IP port: Permission denied
2021-09-10T11:59:40.410951+08:00 0 [ERROR] Do you already have another mysqld server running on port: 443 ?
2021-09-10T11:59:40.410963+08:00 0 [ERROR] Aborting

cause of the problem:

Privileged port: It means that under Linux system, only programs run by the root user can use privileged ports (ports below 1024). If you use the privileged port under a normal user, an error will be reported.

The port 443used by the business is obviously less than 1024, so it is a privileged port. This requires that when starting the process, it must be started as root, but the work user (general user) is specified in the my.cnf file ) To start, it is definitely not the `root` user, so it can not be started, but the error content of mysql is confusing

solution

Change the user=work in the configuration file to user=root, and then execute it as the root user:

root-shell> /home/work/mysql_3307/bin/mysqld_safe --defaults-file=/home/work/mysql_3307/etc/my.cnf &

The contents of the /home/work/mysql_3307/etc/my.cnf file are as follows:

[client]
port = 443
socket = /home/work/mysql_3307/tmp/mysql.sock

[mysqld]
# Change work to rootuser = root
port = 443
socket = /home/work/mysql_3307/tmp/mysql.sock
datadir = /home/work/mysql_3307/data
basedir = /home/work/mysql_3307
pid_file = /home/work/mysql_3307/tmp/mysql.pid
log-error = /home/work/mysql_3307/log/mysql.err
default-time-zone                                               = "+08:00"
thread_handling                                                 = pool-of-threads
thread_pool_stall_limit                                         = 50
thread_pool_oversubscribe                                       = 20
performance_schema                                              = 1
log_slave_updates
log_timestamps                                                  = SYSTEM
general_log = /home/work/mysql_3307/log/mysql.log
general_log = /home/work/mysql_3307/log/mysql.log
log_warnings
slow_query_log
slow_query_log_file = /home/work/mysql_3307/log/slow.log
tmpdir = /home/work/mysql_3307/tmp
created at:12-13-2021
edited at: 12-13-2021: