Open In App

How to Change Default MySQL/MariaDB Port in Linux?

Last Updated : 16 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The default port that the MySQL database server runs under Linux is 3306/TCP.  Use the commands below to change the default MySQL/MariaDB Database port in Linux.

vi /etc/mysql/mariadb.conf.d/50-server.cnf

How to Change Default MySQL/MariaDB Port in Linux

Search for the line MYSQL, find port under this line, and replace port values accordingly.

[mysqld]  
port = 12345

How to Change Default MySQL/MariaDB Port in Linux

After adding the port save the file and then replace the MySQL port variable to match your own port number.

How to Change Default MySQL/MariaDB Port in Linux

To verify the port configuration for MySql DB use the ss command.

# ss -tlpn | grep mysql
# netstat -tlpn | grep mysql

How to Change Default MySQL/MariaDB Port in Linux

You can also display the MySQL port by logging in to the MySQL database, use the -p flag to make remote connections to the MySQL database.

# mysql -h localhost -u root -p -P 12345

How to Change Default MySQL/MariaDB Port in Linux

To make a remote connection with the MySQL database, then you have to explicitly configure it to allow the connection.

How to Change Default MySQL/MariaDB Port in Linux

Remotely login to MySQL server via the below command

# mysql -h 192.168.1.1 -P 12345 -u root -p  

Now once you have changed the MySQL server database, you have to now update your distribution firewall protocols to allow new connections from the TCP port so that clients can remotely connect to the database.



Next Article
Article Tags :

Similar Reads