1.lsof -i:端口号
[root@localhost ~]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 2398 mysql 22u IPv6 22741 0t0 TCP *:mysql (LISTEN)
可以看出3306端口已经被mysql服务占用,PID为2398。(我们想结束mysql服务的时候,可以直接kill掉这个进程PID.)
2.netstat -anp | grep 端口号
[root@localhost ~]# netstat -anp|grep 3306
tcp6 0 0 :::3306 :::* LISTEN 2398/mysqld
[root@localhost bin]# netstat -tunlp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 2398/mysqld
可通过netstat –help查看各参数意义
补充
可通过ps命令直接查看进程(-aux 显示所有状态)
[root@localhost bin]# ps -aux | grep mysql
mysql 2398 0.0 18.3 1127812 186548 ? Sl 11:39 0:05 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 6574 0.0 0.0 112652 960 pts/2 R+ 15:35 0:00 grep --color=auto mysql
[root@localhost bin]# ps -ef | grep mysql
mysql 2398 1 0 11:39 ? 00:00:05 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 6629 6338 0 15:40 pts/2 00:00:00 grep --color=auto mysql