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.
[mysqld] 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.