Search code examples
mysqlterminalportnetstat

In mac terminal, how to check which port mysql is running?


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?


Solution

  • 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';