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

3

6

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?

Beckerman answered 29/5, 2019 at 1:38 Comment(1)
numbers are converted to names. /etc/services has a mapping. Adding -n to netstat will prevent conversion.Economical
P
28

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';
Porism answered 29/5, 2019 at 2:55 Comment(4)
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.Beckerman
@Beckerman yep, use -n shows numbers(port), and without -n shows localhost.mysql, combine the results can identify the mysql port.Porism
I use: lsof -n -P -i TCP -s TCP:LISTEN | grep mysqlFluoroscopy
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).Snell
H
1

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

Hyperbaton answered 10/1, 2021 at 18:53 Comment(0)
C
1

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

Coakley answered 16/6, 2023 at 15:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.