linux mysql状态、启动、停止、重启命令
1.查看mysql状态
【1】ps -ef|grep mysqld 看看是否有mysqld_safe 和mysqld进程
[root@localhost ~]# ps -ef|grep mysqld
显示结果:
1)root 4052 29869 0 10:25 pts/0 00:00:00 grep mysqld
2)root 30905 1 0 10:14 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
3)mysql 31231 30905 1 10:14 pts/0 00:00:09 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log- error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysqld.sock --port=3306
【2】如果已添加到系统服务中,可以service mysqld status
[root@localhost ~]# service mysqld status
显示结果:
SUCCESS! MySQL running (31231)
2.启动MySQL服务
/etc/init.d/mysqld start
也可以用/etc/init.d/mysqld的简化命令启动MySQL服务:service mysqld start
3.停止MySQL服务
/etc/init.d/mysqld stop
也可以使用服务命令:service mysqld stop
4.重启MySQL服务
/etc/init.d/mysqld restart
也可以使用服务命令:service mysqld restart
输入mysql -u root -p出现错误:-bash: mysql: command not found
输入:alias mysql=/usr/local/mysql/bin/mysql
再重复mysql -u root -p,输入mysql口令即可