Home > Database > Mysql Tutorial > body text

How to set the default port in mysql

PHPz
Release: 2023-04-17 16:49:43
Original
3931 people have browsed it

MySQL is a commonly used open source relational database management system. Many websites and applications use MySQL as their main database. In MySQL, a port is the network address used to establish a connection with the database. By default, MySQL uses port 3306, which means that if you want to connect MySQL to any other port, you need to modify the MySQL configuration.

If you need to change the port number of the MySQL service to a different port number, you can easily do so with the following steps.

Step 1: Edit the MySQL configuration file
First, you need to edit the MySQL configuration file my.cnf, which saves the configuration information of the MySQL service. To find the path to the my.cnf file, you can run the following command in the command line:

sudo find / -name my.cnf

This will find the my.cnf file on your system s position. After locating the my.cnf file, you can open it with any text editor.

Step 2: Change the MySQL port
In order to change the MySQL port, you need to find the "[mysqld]" line in the my.cnf file. Add the following line below this line:

port = your desired port number

For example, if you want to change the port number of the MySQL service to 9000, you can change it to:

[mysqld]
port = 9000

You can choose any free port number, but make sure it is not in use by another process. If you want to use this port, you need to open it in your firewall.

Step 3: Save the changes and restart the MySQL service
After completing the changes, please save the my.cnf file and restart the MySQL service for the changes to take effect. The MySQL service can be restarted in a terminal window with the following command:

sudo service mysql restart

After restarting the service, MySQL will be running on the new port and the MySQL service will be loaded with the new configuration.

Summary
MySQL default port number is 3306. If you need to change the MySQL port number, you can change it by editing the MySQL configuration file my.cnf. Make sure to select an unused port number and restart the MySQL service after changing the port number for the changes to take effect.

The above is the detailed content of How to set the default port in mysql. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!