1. Modify the MySQL port under Windows
Windows is one of the most common operating systems when using MySQL. The following will introduce how to modify the MySQL port in the Windows operating system.
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
The configuration file of MySQL in the Windows system is stored 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
On many servers, the Linux operating system is very common, so it is also very common to modify the MySQL port in the Linux environment. 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
The location of the MySQL configuration file in the Linux system is in the file "/etc /mysql/my.cnf". 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. When you restart the MySQL service, you will notice that the MySQL service has started listening for connections and uses the port number you specified.
The above is the detailed content of How to change the MySQL port number under different operating systems. For more information, please follow other related articles on the PHP Chinese website!