1.1 Execute the command su to switch to the root account (the password will not be displayed when entering the password, but it has actually been entered)
su
1.2 Execute the following command to open the configuration file
/etc/my.cnf is the default configuration file path, if you have modified the path, change /etc/my.cnf to the modified path
vi /etc/my.cnf
1.3 Modify/add the port (port number) parameter after opening the configuration file
Press the INSERT key on the keyboard to modify the configuration file. After the modification is complete, press the ESC key on the keyboard to exit the modification, and finally enter : wq! to save the modification
1.4 Restart MySQL
1.4.1 After modifying/adding the port number, execute the following command to restart MySQL
systemctl restart mysqld
1.4.2 Restart fails and an error occurs (if there is no error, just skip to the end of the article)
1.4.3 Execute the following command to view the error
journalctl -xe
1.4.4 You can see that the error is reported because it was intercepted by Selinux
1.4.5 Execute the following command to allow MySQL to use port number 3000
(端口号改成你自己设置的)
semanage port -a -t mysqld_port_t -p tcp 3000
1.4.6 Execute the following command again to restart MySQL to successfully modify the port number
systemctl restart mysqld
1.5 Check the port number
1.5.1 Log in to MySQL and execute the following command to view the port number
show global variables like 'port';