How to find out port of MySQL Server?


To find the port of the MySQL server, the command show can be used. Its syntax is as follows −

show variables where variable_name=’port’;

The above syntax is used to get the port number of the MySQL server using the following query −

mysql> show variables where variable_name = 'port';

After executing the above command, port of MySQL server is obtained as 3306. This can be seen in the following output −

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.01 sec)

Alternatively, the system variable @@port can also be used to find the MySQL server port. This is demonstrated by the following query −

mysql> SELECT @@port;

The output of the above query is as follows −

+--------+
| @@port |
+--------+
| 3306   |
+--------+
1 row in set (0.00 sec)

The above output also gives the port of MySQL server as 3306.

Updated on: 24-Jun-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements