Modify the MySQL port number through the configuration file in Linux (CentOS)

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

5bfae902709845b28ec2f7cbd9a1c309.png

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)

6ca1d6d000ca4c0ebb694802fda22379.png

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 Selinux6ac8805afe2246e78184697eb6c3d2ea.png

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';
8e835c0121e44474837bf8c61898c270.png
My port number is shown in the picture

Guess you like

Origin blog.csdn.net/Coin_Collecter/article/details/130127216