Home > Database > Mysql Tutorial > Modify mysql port

Modify mysql port

WBOY
Release: 2023-05-14 10:25:08
Original
15401 people have browsed it

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”
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

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

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
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. 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!

source:php.cn
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