How to modify the port number: 1. Log in to mysql; 2. Use "show global variables like 'port';" to view the port number; 3. Edit the "/etc/my.cnf" file and find "port ” item and change its value to the required port number; 4. Restart mysql.
The operating environment of this tutorial: linux5.9.8 system, mysql8 version, Dell G3 computer.
Step one: Log in to mysql
mysql -u root -p//输入密码
Step two: Check the port number
Use the command show global variables like 'port';
mysql> show global variables like 'port'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3306 | +---------------+-------+ 1 row in set (0.00 sec) mysql>
3306 is the port number.
Step 3: Modify the port
Edit the /etc/my.cnf file and find the mysql configuration filemy In the port line of .cnf, just change the previous 3306 port to what you want.
Early versions may be the my.conf file name, add port parameters, and set the port. Pay attention to this The port is not in use, save and exit.
[root@test etc]# vi my.cnf[mysqld]port=3506 ##就是这一行 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock
I did not fully display the configuration file of mysql. It is enough to find the port, and then :wq
Launch and save
systemctl restart mysql 或者 /etc/init.d/mysqld restart
Related recommendations: mysql video tutorial, "Linux tutorial"
The above is the detailed content of How to modify the port number of mysql under linux. For more information, please follow other related articles on the PHP Chinese website!