MySQL: Change Default Port Under Linux / UNIX

MySQL: Change Default Port Under Linux / UNIX

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:

  1. Open the MySQL configuration file in a text editor. For example:
ref‮ual:ot re‬tturi.com
sudo nano /etc/mysql/my.cnf
  1. Find the [mysqld] section in the configuration file.

  2. 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
  1. Save the configuration file and exit the text editor.

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

Created Time:2017-10-16 14:38:54  Author:lautturi