Home >Database >Mysql Tutorial >Modify mysql port
MySQL is a very popular relational database management system commonly used in fields such as web development. By default, MySQL uses port 3306 to listen for connections. However, in some cases, you may need to change the port number for MySQL. This article will introduce how to change the MySQL port number under different operating systems.
1. Modify the MySQL port under Windows
Windows is one of the most widely used operating systems for MySQL. Here is how to modify the MySQL port under Windows.
1. Stop the MySQL service
Before you start changing the MySQL port, make sure you have stopped the MySQL service. Under Windows, the MySQL service can be found in the Services tab. Find the MySQL service in Service Manager and stop it.
2. Edit the my.cnf file
Under Windows, the MySQL configuration file is located in the "/my.ini or my.cnf" file in the installation directory. Open the file using a text editor.
Look for the "[mysqld]" tag. Then look for the following line:
# You can listen on a specific IP address instead of all IP addresses. #bind-address = “127.0.0.1”
Comment out the line if it already has a binding address. Now add the following two lines and change the port number to your desired port number:
port = 1234 # 更改为您想要的端口号 bind-address = “127.0.0.1”
3. Restart the MySQL service
Save and close the configuration file. Now start the MySQL service again. You will see that the MySQL service has started listening for connections using the port number you specified.
2. Modify the MySQL port under Linux
Many servers use the Linux operating system, so it is very common to modify the MySQL port under Linux. Here's how to change the MySQL port under Linux.
1. Stop the MySQL service
Before you start changing the MySQL port, make sure you have stopped the MySQL service. Under Linux, to stop the MySQL service, you can use the following command:
sudo service mysql stop
2. Edit the my.cnf file
Under Linux, the MySQL configuration file is located in "/etc/mysql/my .cnf" file. Open the file using a text editor.
Look for the "[mysqld]" tag. Then look for the following line:
# You can listen on a specific IP address instead of all IP addresses. #bind-address = 127.0.0.1
Comment out the line if it already has a binding address. Now add the following two lines and change the port number to your desired port number:
port = 1234 # 更改为您想要的端口号 bind-address = 127.0.0.1
3. Restart the MySQL service
Save and close the configuration file. Then restart the MySQL service and you will see that the MySQL service has started listening for connections using the port number you specified.
Summary
In order to modify the MySQL port number, you need to edit the MySQL configuration file. Under Windows, this file is located in "/my.ini or my.cnf", while under Linux, this file is located in "/etc/mysql/my.cnf". In this file you need to look for the "[mysqld]" tag and change the "port" option to use the port number you want. Then restart the MySQL service for the changes to take effect.
You can easily change the MySQL port number using the same steps whether under Windows or Linux. This will make it easier for you to install and run MySQL on multiple servers to better suit your needs.
The above is the detailed content of Modify mysql port. For more information, please follow other related articles on the PHP Chinese website!