Mysql can be configured to run other ports other than the default port (of 3306). So what will you do when you need to find the port on which a mysql server runs on. If you don’t have access to the server files and can access the server only using the mysql client, the only way to know this is by checking the Global Variable set. We can see all variables by issuing the command:
SHOW GLOBAL VARIABLES;
But this will give you a huge list of necessary and unnecessary values. So if we know what we want ( like for now we want the Port on which it is running) we can use the LIKE command along with it. LIKE will get you variables that have the keyword specified in its name.
Hence to get the port number on which the mysql is running by the command:
SHOW GLOBAL VARIABLES LIKE 'PORT';
Which shows result as:
| Variable_name | Value |
| port | 3336 |
Hence the port which this mysql is running on is 3336.