我如何检查它在unix服务器上运行的端口,我必须上传应用程序。
我做了
mysql> SHOW GLOBAL VARIABLES LIKE'PORT';
这表明我正在使用port 3306
并继续我的search错误。
真正了解哪个应用程序正在监听哪个接口以及使用哪个端口的最好方法是使用netstat
您可以以root身份执行此操作:
netstat -tlnp
它会列出所有这样的监听服务:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25934/mysqld tcp6 0 0 :::22 :::* LISTEN 7964/dropbear
最后一列显示,mysqld将自己绑定到侦听所有接口的3306端口。
事实上,这适用于一切,不仅仅是mysql。 你也可以使用它的非TCP套接字。
除非在/etc/my.cnf
configuration文件中指定另一行,否则MySQL默认使用端口3306。
除非你的/etc/my.cnf
包含类似的东西
[mysqld] port = 3308
那么很可能你正在使用默认端口。
如果您确实要确认它在端口上运行,则可以在进程启动时远程login端口:
telnet localhost 3306
你会看到它报告你连接到MySQL。
实际上,你可以使用ps和grepfind进程的PID:
ps -ef | grep mysql
然后把这个pid放到lsof中打印出所有打开的文件描述符。 你会发现进程绑定的端口靠近顶端。
另一种方法已列出(不是很好,但嘿,它的作品)。
prompt>lsof -n | grep 'mysql.*TCP' mysqld 1564 mysql 10u IPv4 3246456 0t0 TCP *:mysql (LISTEN) prompt>cat /proc/1564/net/tcp sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 0: 11AC11AC:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 14299 1 ffff88012a429a00 299 0 0 2 -1 1: 017AA8C0:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 13871 1 ffff880129962080 299 0 0 2 -1 2: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 12596 1 ffff880129960000 299 0 0 2 -1 3: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 11459 1 ffff88012a429380 299 0 0 2 -1 4: 00000000:8D58 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 11315 1 ffff88012a428d00 299 0 0 2 -1 5: 00000000:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 12940 1 ffff880129960680 299 0 0 2 -1 6: 0100007F:177A 00000000:0000 0A 00000000:00000000 00:00000000 00000000 500 0 3600557 1 ffff8800672dee80 299 0 0 2 -1 7: 0100007F:177B 00000000:0000 0A 00000000:00000000 00:00000000 00000000 500 0 3603871 1 ffff88012a42ee80 299 0 0 2 -1 8: 0100007F:177C 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 3608169 1 ffff88012a42f500 299 0 0 2 -1 9: 0100007F:177D 00000000:0000 0A 00000000:00000000 00:00000000 00000000 500 0 3615687 1 ffff88012a42e180 299 0 0 2 -1 10: 0100007F:00C7 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 3608454 1 ffff8800672db400 299 0 0 2 -1 11: 00000000:0CEA 00000000:0000 0A 00000000:00000000 00:00000000 00000000 27 0 3246456 1 ffff8800672dba80 299 0 0 2 -1 12: 00000000:024B 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 12944 1 ffff880129961380 299 0 0 2 -1 13: 00000000:006F 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 10657 1 ffff88012a428680 299 0 0 2 -1 14: 00000000:01D1 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 12942 1 ffff880129960d00 299 0 0 2 -1 15: 0100007F:1DD2 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 3631325 1 ffff8800672da700 299 0 0 2 -1 16: 0100007F:990B 0100007F:177B 01 00000000:00000000 02:0002F5D8 00000000 500 0 3610110 2 ffff8800672df500 20 3 26 4 19 17: 0100007F:177B 0100007F:990C 01 00000000:00000000 00:00000000 00000000 500 0 3610124 1 ffff88012a42d480 20 3 0 5 -1 18: 0100007F:990D 0100007F:177B 01 00000000:00000000 02:00031144 00000000 500 0 3610142 2 ffff8800672d9380 20 3 0 5 -1 19: 0100007F:177B 0100007F:990B 01 00000000:00000000 00:00000000 00000000 500 0 3610111 1 ffff8800672dc100 21 3 29 4 -1 20: 0100007F:177B 0100007F:9949 01 00000000:00000000 00:00000000 00000000 500 0 3611026 1 ffff8800672dad80 20 3 0 5 -1 21: 0100007F:9912 0100007F:177B 01 00000000:00000000 02:0005D3D3 00000000 500 0 3610249 2 ffff8800672de180 20 3 0 3 -1 22: 0100007F:177B 0100007F:990D 01 00000000:00000000 00:00000000 00000000 500 0 3610143 1 ffff8800672de800 20 3 1 5 -1 23: 11AC11AC:0016 480111AC:9074 01 00000000:00000000 02:0002BCFF 00000000 0 0 3608096 2 ffff88012a428000 20 3 1 5 16 24: 11AC11AC:0016 480111AC:8485 01 00000000:00000000 02:0005819F 00000000 0 0 3615610 2 ffff88012a42c100 20 3 1 5 -1 25: 0100007F:177B 0100007F:9923 01 00000000:00000000 00:00000000 00000000 500 0 3610494 1 ffff88012a42ce00 20 3 0 5 -1 26: 0100007F:990F 0100007F:177B 01 00000000:00000000 02:0003117F 00000000 500 0 3610209 2 ffff8800672dd480 20 3 0 5 -1 27: 0100007F:9949 0100007F:177B 01 00000000:00000000 02:0005D3D3 00000000 500 0 3611025 2 ffff8800672ddb00 20 3 0 3 -1 28: 0100007F:90CF 0100007F:177B 01 00000000:00000000 02:00004637 00000000 500 0 4049147 2 ffff8800672dc780 20 3 1 5 -1 29: 11AC11AC:0016 480111AC:C273 01 00000000:00000000 02:00021D06 00000000 0 0 3600488 4 ffff88012a42a700 20 6 31 4 34 30: 0100007F:177B 0100007F:90CF 01 00000000:00000000 00:00000000 00000000 500 0 4049148 1 ffff8800672d8680 20 3 0 5 -1 31: 11AC11AC:0016 480111AC:C7C3 01 00000000:00000000 02:00093A92 00000000 0 0 3603799 2 ffff88012a42ba80 20 3 26 5 31 32: 0100007F:177B 0100007F:9912 01 00000000:00000000 00:00000000 00000000 500 0 3610250 1 ffff8800672da080 20 3 0 5 -1 33: 0100007F:177B 0100007F:990F 01 00000000:00000000 00:00000000 00000000 500 0 3610210 1 ffff8800672d9a00 20 3 1 5 -1 34: 0100007F:990C 0100007F:177B 01 00000000:00000000 02:00031147 00000000 500 0 3610123 2 ffff88012a42ad80 20 3 1 5 -1 35: 0100007F:9923 0100007F:177B 01 00000000:00000000 02:0005D3D3 00000000 500 0 3610493 2 ffff88012a42e800 20 3 16 3 -1 prompt>grep '^mysql:' /etc/passwd mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash prompt>
uid 27行是mysqld进程的侦听套接字,0CEA是3306的hex。
好吧,这在我的Linux机器上工作,但我不确定Unix将存储cnf文件在同一个地方。
cat /etc/mysql/my.cnf | grep'port'