How to Determine Which Port MySQL is Running On

MySQL defaults to port 3306 when installed but sometimes for another reason, it may be listening on a different port. In this post, I list some ways in which you can find out which port your MySQL instance is running on.

Using the MySQL configuration file to determine which port it is running on

If you are running linux, then this is an easy one liner. On my test machine, my config is stored in /etc/mysql:

cat /etc/mysql/my.cnf | grep port

On my test machine this returns

port            = 3306

If you are running Windows, then find your my.ini file and open it in a text editor such as notepad. Perform a search for the term – “port”

Using the MySQL client to determine the MySQL port

MySQL can tell you which port it is running on. Log into it and use the “show variables like ‘port%'”;

[email protected]:~# mysql -uroot -p;
mysql> show global variables like 'port%';
| Variable_name | Value |
| port          | 3306  |
1 row in set (0.00 sec)

If you are using a client such as MySQL Workbench, you use the above syntax or click on “Server Status” over on the left hand side, for example in Windows, it looks like this:

how to find mysql port using MySQL workbench

Using the netstat command to determine which port MySQL is running on

This command is so useful on a unix or windows operation system – “netstat” which is short for “network statistics”

netstat -tln | grep mysql

In the results below (unix OS), the port is listed in this section as “0

tcp        0      0  *               LISTEN      1115/mysqld

If running on windows, you could do

netstat -anob

It’s a little hard then to find the one which is relevant as the list can be quite large, scrolling past quickly. It’s possible to pipe it to make the output page or dump it to file and then look for mysqld.exe in the list.

Paging example

netstat -anob | more

Dumping to file example

netstat -anob > output.txt

In each case find the mysqld.exe lines where the status is LISTENING

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestBuffer this pageShare on RedditShare on StumbleUpon
About Andy Hayes

Andy Hayes is a DBA working with SQL Server since version 7.0. He has a wonderful wife and two beautiful children. He loves database technology, playing cricket, and blogging. He is passionate about sharing his experiences as a DBA and learning more to further his understanding and knowledge. You can follow me on Twitter, check out my Facebook page or follow me on

Speak Your Mind