To change the default port that MySQL listens on under Linux or Unix, you will need to edit the MySQL configuration file. The MySQL configuration file is usually located at /etc/my.cnf
or /etc/mysql/my.cnf
.
To change the default MySQL port, follow these steps:
sudo nano /etc/mysql/my.cnf
Find the [mysqld]
section in the configuration file.
Add the following line to the [mysqld]
section, replacing port_number
with the desired port number:
port=port_number
For example, to change the port to 3307, you would add the following line:
port=3307
Save the configuration file and exit the text editor.
Restart the MySQL server to apply the changes. You can do this using the following command:
sudo service mysql restart
After the MySQL server has been restarted, it will listen on the new port number.