

All we have to do is to change the settings of the file.ĭepending on which MySQL server package is installed on your machine the extension of the file may change but it will always be either ini or cnf with the name my or mysql.cnf or mysqld.cnf. This file is present in the folder where your database is installed. The information about the MySQL configurations is stored inside the my.ini of my.cnf file. Now, we will see where the default port of MySQL is configured and specified and how we can change it to any other port we want. In this way, we can connect to the MySQL database server by using the command-line on any platform. The command used to connect to the database server using its default port and root access is as follows –īy specifying the particular port using which you want to establish the TCP/IP connection to the MySQL database server, you can use the following command –įor both these commands, we had to first log in as a superuser using su command. We can connect to our MySQL database server using the command-line terminal with the help of TCP/IP protocol connection by connecting to a specific port that is listening to the network connections as we saw in the output of the above command that 3306 port is listening. The output indicates that the port with port number 3306 is listening at localhost 127.0.0.1 address and uses TCP socket and protocol for connection. That will display all connections with 3306 port.

In windows, you can make the use of the following query –

In our case, we are using grep that states to search with keyword “mysql” specified further.Īlternatively, you can use the following command – In the above command, netstat is used to display the status of the net and -a stands for all the connections while | operator is used to specifying the filters and additional information. It tells us that there are 2 connected connections of MySQL and one connection is listening. That gives the following output in my case – To check the port of MySQL on our network in Unix/Linux platforms, we can make the use of the following command – The remote connections are always made using TCP/IP sockets and 3306 as the default port number of Mysql. All these are supported by MySQL that uses TCP/IP socket, Named pipes, or Unix sockets to connect with the network. Mysql database is accessed by multiple clients and users and this leads to the creation of multiple connections and sessions. Mysql -u your_username -e “SHOW GLOBAL VARIABLES LIKE ‘PORT’” In windows, the following command is used to get to know the value of MySQL port. This is the default value of the MySQL port number. We can see that the value of the port variable is 3306.
