Updated March 10, 2023
Introduction to mariadb port
MariaDB port is a number assigned to the socket with which we will establish a connection in order to connect the server and client application in a network. When using it with the MariaDB database server the default port number for MariaDB is 3306. We can configure and change the default port address number to any other port number provided if that particular port address is available and free that is not used by any other application or task. In this article, we will have a look upon what is the port number used in the MariaDB database, how we can use this port number to establish a connection between the MariaDB database server and MySQL client, have a look at some of the examples that use the commands involving MariaDB port.
What is MariaDB port?
The MariaDB port number by default is 3306. Port is basically a number given to a particular socket end where a task can communicate by establishing the connection. MariaDB port is used for the same purpose. We can change the default port number address by some other number as per our requirements by accessing the configuration file and editing and modifying the same or by using the commands from the command prompt. The name of the configuration file in which all the default values to different options and parameters are listed is my. cnf which is located inside the opt/bitnami/mariadb folder. When using the Linux system package the my.cnf configuration file can be founded in the folder opt/bitnami/mariadb/conf/my.cnf file directory.
To check the logs in case if the connection is not established between the MariaDB database server and MySQL client, we can check the log file which tells us about the errors or the reasons for which the MariaDB server was started or stopped the log file can be found in the directory structure having the path opt/bitnami/mariadb/(data or logs)/ mysqld.log which has all the logged details in it.
When we install the MariaDB software which has a trial installer version the port number 3306 is opened automatically which is an inbound rule. Further that the TCP connections can only be opened through port address 3306. In MySQL, you will externally need to open port 3306 and set up it manually.
How to use mariadb port?
When you go for establishing the connection between MySQL client and MariaDB server the default command used is shown below.
After typing the above command, the default parameters taken from the configuration file are as follows –
Host os localhost
User is the login name of ODBC on windows platform or login name of Unix.
Password is not passed as a parameter
The connection is established between client and server but the connection is not connected to a particular database present on the server. –port = address of port number or -P portNumber can be used to specify any other port with which to connect if the default 3306 port address is not used.
For example, when we use the below command –
mysql -h 18.104.22.168 -u payal -p password educbaDatabase -port 3000
The output of the execution of the above command is as shown below where the connection has been established with MariaDB database server configured at 3000 port number –
The user payal will be considered the supplied password will be taken into account and the port address which needs to be reached and established the connection will be 3000 which should be empty and available to use before this command is executed. The database with which the connection would be established is educbaDatabase present in our MariaDB database server. Alternatively, the above command can also be used by specifying the port number with capital P option as shown below –
mysql -h 22.214.171.124 -u payal -p password educbaDatabase -P 3000
That results in the same output and execution as shown below –
mariadb port examples / Use the command –
The port can be used in the MariaDB database server to establish the connection as demonstrated in the above two commands of mysql connection establishment. Further, if we want to change the default port used in MariaDB in a Linux platform then we can follow the below steps –
Make the use of vi command shown in the below example command statement to change the configured port address for the MariaDB database server.
Vi /(opt or etc)/(mysql or mariadb)/ mariadb.conf.d/50-server.cnf that will open up the configuration file on your command prompt itself as shown in the below image –
Here, we will have to search for the [mysqld] section inside which we will look at the port specification which let’s change it for now to 12345 as can be seen from the above image. After this editing inside the file is done, we can save the file and in order to match the port number of our own, we will change and replace the value of the MySQL port variable.
After that, you will have to restart the mysql or MariaDB and then verify the configuration of MariaDB and mySQL for port verification by making the use of the command ss or netstat which can be used by typing in either of the following commands.
Ss -tpln | grep mariadb
Netstat -tlpn | grep mariadb
Or further, we can also go for establishing the remote connection or local connection with you Mysql of MariaDB database by using the option of -P or -port and specifying the configured port number. In our case, let us try to establish the connection by using the port number 12345 and the command statement becomes –
Mysql -h localhost -u root -P 12345
Executing the above command will return the following output as the result –
While establishing the connection remotely, instead of providing localhost in the command, you can mention the ip address of the database server where you are trying to connect. After doing this, you can also update all your firewall protocols in order to use the TCP port specified by you to allow new connections in order to allow clients to connect remotely.
MariaDB port is the number specifying the address where an application should connect to and in the case of MariaDB where MySQL client can connect to MariaDB database server is specified by MariaDB port.
This is a guide to mariadb port. Here we discuss what is the use of port number in MariaDB database, how we can use this port number to establish a connection between the MariaDB database server. You may also have a look at the following articles to learn more –