Mysql 查看端口号

链接: http://blog.itpub.net/blog/post/id/1592460/
标题: MySQL 查看端口的几种方式
作者:lōττéry©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

注释:
今天通过“Navicat for MySQL”工具链接生产环境数据库时,需要输入 mysql“端口”号,所以找到了几种 查看mysql端口的方法,特此整理下提供参考.
默认端口 3306;

OS层

ps 查看当前运行的进程。
[root@lottery ~]# ps aux|grep mysql|grep port
mysql 3148 0.3 17.3 61207592 11430100 ? Sl Mar26 124:05 /usr/sbin/mysqld –basedir=/usr –datadir=/data/public3306/db –plugin-dir=/usr/lib64/mysql/plugin –user=mysql –log-error=/data/public3306/err.log –pid-file=/data/public3306/mysqld.pid –socket=/data/public3306/mysql.sock –port=3306
[root@lottery ~]#

– 参数介绍:
-a :不与 terminal 有关的所有 process ;
-u :有效使用者 (effective user) 相关的 process ;
x :通常与 a 这个参数一起使用,可列出较完整信息。
具体资料:linux ps命令介绍

netstat 命令用于显示各种网络相关信息。
[root@lottery ~]# netstat -antp|grep mysqld| grep LISTEN
tcp 0 0 :::3306 :::* LISTEN 4702/mysqld
[root@lottery ~]#

–参数介绍:
-a (all)显示所有选项,默认不显示LISTEN相关
-t (tcp)仅显示tcp相关选项
-n 拒绝显示别名,能显示数字的全部转化成数字。
-p 显示建立相关链接的程序名
提示:LISTEN和LISTENING的状态只有用-a或者-l才能看到
具体资料:Linux netstat命令详解

查看 /etc/services 文件 记录网络服务名和它们对应使用的端口号及协议。
[root@lottery ~]# grep MySQL /etc/services
mysql 3306/tcp # MySQL
mysql 3306/udp # MySQL
mysql-cluster 1186/tcp # MySQL Cluster Manager
mysql-cluster 1186/udp # MySQL Cluster Manager
mysql-cm-agent 1862/tcp # MySQL Cluster Manager Agent
mysql-cm-agent 1862/udp # MySQL Cluster Manager Agent
mysql-im 2273/tcp # MySQL Instance Manager
mysql-im 2273/udp # MySQL Instance Manager
mysql-proxy 6446/tcp # MySQL Proxy
mysql-proxy 6446/udp # MySQL Proxy
sphinxql 9306/tcp # Sphinx search server (MySQL listener)
[root@lottery ~]#

查看 mysql配置文件。
[root@lottery ~]# grep port /etc/my.cnf
port = 3306
[root@lottery ~]#
## 修改端口的话 直接修改/etc/my.cnf文件 后重启mysql数据库 /etc/init.d/mysqld restart 即可。

DB 层

mysql> show variables like ‘port’;
+————–+———+
| Variable_name | Value |
+—————+——–+
| port | 3306 |
+————–+———-+
mysql>

小贴士 : 查看版本 mysql> select version();

猜你喜欢

转载自blog.csdn.net/qq_32583639/article/details/81805311