5

I've done some research and found several places where people suggest using netstat to check which port a particular process is using. But here is what I got:

myMac:~/Documents$ netstat -ap tcp | grep -i "listen"

tcp4       0      0  localhost.mysql        *.*                    LISTEN  

What does localhost.mysql say about the port number?? I'm expecting a 4 digit number like 3306. Any thoughts?

Kid_Learning_C
  • 2,605
  • 4
  • 39
  • 71
  • numbers are converted to names. /etc/services has a mapping. Adding `-n` to netstat will prevent conversion. – danblack May 29 '19 at 02:55

3 Answers3

23

You should use -n for netstat to show network addresses as numbers.

netstat -nap tcp | grep -i "listen"
man netstat
-n Show network addresses as numbers (normally netstat interprets addresses and attempts to display them symbolically).  This option may be used with any of the display formats.

Or use lsof:

lsof -n -P -i TCP -s TCP:LISTEN

Or use mysql client to check mysql port:

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
0xTang
  • 776
  • 7
  • 11
  • 2
    Thanks for the answer. Just a note: `netstat -nap tcp | grep -i 'listen'` would't work since you can't tell which one is mysql from the results - the results are all numbers and there is no string to identify for mysqld. But the other solutions work. – Kid_Learning_C May 30 '19 at 15:06
  • @Kid_Learning_C yep, use -n shows numbers(port), and without -n shows **localhost.mysql**, combine the results can identify the mysql port. – 0xTang May 31 '19 at 02:07
  • 1
    I use: `lsof -n -P -i TCP -s TCP:LISTEN | grep mysql` – Hermann Schwarz Jul 15 '21 at 10:37
  • Only the last solution worked for me. The first does not show what is mysql. The second failed to identify a running mysql server. Perhaps something to do with running mysql via preferences panel in macos (Monterey). – StayCool Jan 03 '23 at 06:56
0

if you have Workbench installed then just open it and check the port. most likely, it will be 3306. see screenshot attached enter image description here

kush
  • 486
  • 4
  • 6
0

Note that if your process is running as a LaunchDaemon you will need to use sudo to see it.

sudo lsof -n -P -i TCP -s TCP:LISTEN