How to Change Default MySQL/MariaDB Port in Linux?
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.
Search for the line MYSQL, find port under this line, and replace port values accordingly.
port = 12345
After adding the port save the file and then replace the MySQL port variable to match your own port number.
To verify the port configuration for MySql DB use the ss command.
# ss -tlpn | grep mysql
# netstat -tlpn | grep mysql
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
To make a remote connection with the MySQL database, then you have to explicitly configure it to allow the connection.
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!