Is not possible change MySQL's port at Fedora Server 36

For Fedora Server 36 was installed MySQL 8 Community through the .rpm from MySQL Community Downloads. Now according with the Editing Conf. Files section is indicated to use the /etc/my.cnf.d/community-mysql-server.cnf file, but it does not exist, it because the /etc/my.cnf.d/ directory is empty, the truly valid file is /etc/my.cnf/ where it currently contains:

[mysql]
#
# many comments
#
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/run/mysqld/mysqld.pid

Well if is added port=3307 as

[mysql]
#
# many comments
#
port=3007
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/run/mysqld/mysqld.pid

saved the file and executed the following commands:

sudo systemctl stop mysqld
sudo systemctl start mysqld

for the second command fails with the following message:

Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xeu mysqld.service" for details

For the systemctl status mysqld.service command shows

With the journalctl -xeu mysqld.service command shows

From above something Error 13: (Permission denied)

With the sudo cat /var/log/mysqld.log command shows

From above:

Can't start server: Bind on TCP/IP port: Permission denied
Do you already have another mysqld server running on port: 3307?

With the sudo lsof -i -P command shows

What is missing or what should be done?

Note: I have this situation even with port 3308. Of course if is declared 3306 explicitly all work fine.

The firewall defines mysql as using 3306 and that is open so you can connect to it. Port 3308 may be blocked by the firewall or by selinux.

You may find that you need to explicitly tell the firewall that 3308 is associated with mysql. You may also find that something in selinux is not allowing that service to access that port.

The selinux possibility can quickly be tested by setting selinux to permissive with sudo setenforce 0 then trying to start mysql. sudo setenforce 1 will restore selinux to enforcing.

The firewall possibility can be quickly tested by disabling the firewall with sudo systemctl stop firewalld.service then trying to start mysql. The firewall can be restarted with sudo systemctl start firewalld.service

please check this guide, section selinux police:

Regards.,

1 Like

Thanks, the solution was execute the semanage port -a -t mysqld_port_t -p tcp 3307 command.

Thanks for the feedback, it was the correct path - and of course it is based on your experience - because I am not an expert in Linux - why the error message was not more clearer from the beginning? Indicating something like " … port blocked by SELinux …" ?

1 Like

The reason for the less clear message is that mysql does not know about selinux and does not interact with selinux. Mysql had no indications of why it could not open the port. Since mysql was blocked by selinux from opening the port it failed.

The error log showed the basic response as a possible cause, not a definitive cause.

If you were to look at the journalctl log at the same time as mysql failed to open that port it probably showed that selinux blocked the action as an audit entry.

1 Like

Thanks for the feedback, time for me to learn more the journalctl command