在Linux平台下,可以采用如下命令查看MySQL服务的状态:
[root@localhost ~]# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 2182/./hpiod
tcp 0 0 0.0.0.0:5989 0.0.0.0:* LISTEN 2611/cimservermain
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2369/mysqld
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1833/portmap
tcp 0 0 0.0.0.0:784 0.0.0.0:* LISTEN 1874/rpc.statd
...
[root@localhost ~]#
其中端口号3306是MySQL服务器监听端口;
启动和关闭MySQL有两种方式
1)命令式方式
root@localhost sbin]# cd /usr/bin/
[root@localhost bin]# ./mysqld_safe &
[1] 12788
[root@localhost bin]# 150507 01:25:46 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.
150507 01:25:47 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@localhost bin]# mysqladmin -u root -p shutdown
Enter password:
150507 01:26:48 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended
[1]+ Done ./mysqld_safe
[root@localhost bin]#
2)服务的方式
[root@localhost bin]# service mysql start
Starting MySQL.. [ OK ]
[root@localhost bin]# service mysql restart
Shutting down MySQL.. [ OK ]
Starting MySQL.. [ OK ]
[root@localhost bin]# service mysql stop
Shutting down MySQL.. [ OK ]
[root@localhost bin]#