Open In App
Related Articles

How to Change Default MySQL/MariaDB Port in Linux?

Improve Article
Improve
Save Article
Save
Like Article
Like

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.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 16 Feb, 2021
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials