How to check which service is running on a particular port

I use MAMP for developing the Zention website locally (it’s an awesome platform which contains the Apache, MySQL and PHP stack which runs on Mac – check it out if you haven’t already!). Anyway, I wanted to hook up SquirrelSQL (my favourite JDBC client) so I could do some development work against the database for the website, but I wasn’t sure of the port MySQL was using (it wasn’t 3306 which is the default).

I found the port in the MAMP settings, but it reminded me of a useful command I wanted to share lsof (which stands for “list open files”): this shows which process is running on a specific port and works on Mac and any Unix/Linux system.

My database was running on port 8889 and lsof shows this:

$ lsof -i :8889
COMMAND  PID          USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mysqld  3338 matthewspeake   19u  IPv6 0x3e15923d3d42748b      0t0  TCP *:ddi-tcp-2 (LISTEN)

It can be useful to check which process (and also if the process you think) is running on a given port.

Top