Home > Database > Mysql Tutorial > How to change the MySQL port number under different operating systems

How to change the MySQL port number under different operating systems

WBOY
Release: 2023-05-27 11:19:52
forward
1633 people have browsed it

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”
Copy after login

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”
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template