
When you are connected to the MySQL server and want to check the port your client is using to connect with the MySQL server, you can retrieve the value of the variable named port that stores the port number used for the connection.
#Mysql database port how to
Additionally, it will explain how to modify the default port used for connecting to MySQL by making changes in the configuration file. This article will demonstrate retrieving the currently used ports, checking your MySQL port, and connecting with the MySQL database server using the default MySQL port. MySQL utilizes TCP/IP sockets to establish connections with remotely located clients. All these protocol values serve the purpose of establishing and maintaining connections to remote or local servers. There are four types of protocol values, namely, TCP, used in all operating systems PIPE and MEMORY, used in the Windows operating system and SOCKET, used in Unix/Linux operating systems.
#Mysql database port update
# mysql -h 192.168.1.159 -P 12345 -u root -pįinally, once you’ve changed MySQL/MariaDB database server port, you need to update your distribution Firewall rules to allow incoming connections to the new TCP port so that remote clients can successfully connect to the database.Hadoop, Data Science, Statistics & others Remotely log in to MySQL server via a command line client on the new port by issuing the below command. MariaDB > grant all privileges on *.* to identified by 'strongpass' In case of remote connection to MySQL database, the root user must be explicitly configured to allow incoming connections form all networks or just an IP address, by issuing the below command in MySQL console: # mysql -u root -p But the TCP port number must be explicitly specified in case of command line remote connections to MySQL database using the -P flag. However, be aware that all connections to MySQL on localhost are made via MySQL unix domain socket, not via the TCP socket.

You can also display the new MySQL port by logging in to MySQL database with root account and issue the below command. In order to verify if the port configuration for MySQL/MariaDB database server has been successfully applied, issue netstat or ss command and filter the results via grep command in order to easily identify the new MySQL port. # semanage port -a -t mysqld_port_t -p tcp 12345 Again, replace MySQL port variable to match your own port number. Next, add the below SELinux rule to bind MySQL socket on the new port and restart the database daemon to apply changes, by issuing the following commands.
#Mysql database port install
Īfter you’ve added the new MySQL/MariaDB port, save and close the configuration file and install the following package under CentOS 7 in order to apply the required SELinux rules to allow the database to bind on the new port.

Search for the line stat starts with and place the following port directive under statement, as shown in the below file excerpts. In order to change the default MySQL/MariaDB database port in Linux, open MySQL server configuration file for editing by issuing the below command. The default port that MySQL database server is running under Linux and Unix is 3306/TCP. In this guide we’ll learn how to change the default port that MySQL/MariaDB database binds in CentOS 7 and Debian-based Linux distributions.
