Changing MySQL Port Number on CentOS 7

Changing MySQL Port Number on CentOS 7

When deploying MySQL on a CentOS 7 system, sometimes you need to change the default port number. This article explains how to change the port number of a MySQL database on CentOS 7.

Steps

1. Connect to the MySQL Database

First, connect to MySQL using the command:

mysql -u root -p

Enter your password to access the MySQL prompt.

2. Check Current Port Number

At the MySQL prompt, run the following SQL to view the current port:

SHOW VARIABLES LIKE 'port';

This displays the current port, which is usually 3306.

3. Change the Port Number

Edit the MySQL configuration file my.cnf. Open it with:

vi /etc/my.cnf

Locate the [mysqld] section and add a line to set the new port, for example:

port = 3307

Save and close the file.

4. Restart MySQL Service

Restart MySQL to apply the changes:

systemctl restart mysqld

5. Verify the Change

Reconnect to MySQL and run the same SQL command to confirm the new port:

SHOW VARIABLES LIKE 'port';

You should see the port updated to 3307.

Summary

By following these steps, you can successfully change the MySQL port on CentOS 7. Note that changing the port may require additional network adjustments, so proceed with caution.

Tags: MySQL centos port configuration

Posted on Tue, 12 May 2026 22:48:34 +0000 by watts