【问题标题】:In mac terminal, how to check which port mysql is running?在mac终端中,如何查看mysql在哪个端口运行?
【发布时间】:2019-10-14 13:26:12
【问题描述】:

我进行了一些研究,发现了一些人们建议使用netstat 来检查特定进程正在使用哪个端口的地方。 但这是我得到的:

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

tcp4       0      0  localhost.mysql        *.*                    LISTEN  

localhost.mysql 对端口号说了什么?我期待一个像 3306 这样的 4 位数字。 有什么想法吗?

【问题讨论】:

  • 数字转换为名称。 /etc/services 有一个映射。将-n 添加到 netstat 将阻止转换。

标签: mysql terminal port netstat


【解决方案1】:

您应该使用 -n 来让 netstat 将网络地址显示为数字。

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.

或者使用 lsof:

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

或者使用mysql客户端查看mysql端口:

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

【讨论】:

  • 感谢您的回答。请注意:netstat -nap tcp | grep -i 'listen' 不起作用,因为您无法从结果中分辨出哪个是 mysql - 结果都是数字,并且没有字符串可以识别 mysqld。但其他解决方案有效。
  • @Kid_Learning_C 是的,使用-n显示数字(端口),不使用-n显示localhost.mysql,结合结果可以识别mysql端口。
  • 我使用:lsof -n -P -i TCP -s TCP:LISTEN | grep mysql
【解决方案2】:

如果您安装了 Workbench,则只需打开它并检查端口。最有可能的是 3306。 见附截图

【讨论】:

    猜你喜欢
    • 2015-03-05
    • 2013-09-20
    • 2015-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2020-10-13
    • 2016-10-21
    相关资源
    最近更新 更多