计算机网络/计算机科学与应用/系统/运维/开发

MySQL8 启动与停止及查看状态

一、MySQL启动与停止的多种方式

1、使用服务模式启动与停止

[root@www ~]# sudo service mysql start  // 启动mysql
[root@www ~]# sudo service mysql stop   // 停止mysql

2、使用init.d 方式启动与停止

[root@www ~]# sudo /etc/init.d/mysql start  // 启动mysql
[root@www ~]# sudo /etc/init.d/mysql stop  // 停止mysql

注意:

如果没有找到启动脚本(当执行二进制安装时),则可以 从解压位置进行复制并命名为mysql

> sudo cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysql

3、systemcted 方式启动与停止

[root@www ~]# systemctl start mysqld  // 启动mysql
[root@www ~]# systemctl stop mysqld   // 停止mysql

4、如果不支持systemd,可以使用mysqld_safe启动mysql, mysqld_safe是mysqld的启动脚本,用于保护mysql进程,如果mysqld被杀死,mysqld_safe 会尝试再次启动该进程。

[root@www ~]# mysqld_safe --user=mysql &


停止mysql服务器的运行还有一种mysqladmin:

[root@www bin]# mysqladmin -u root -p shutdown
Enter password: 
2020-07-06T02:05:17.535907Z mysqld_safe mysqld from pid file /usr/local/mysql/data/mysqld.pid ended
[1]+  完成                  mysqld_safe --user=mysql(工作目录:~)
(当前工作目录:/usr/local/mysql/bin)


二、检查MySQL8.0服务器状态

1、使用service  

sudo systemctl status mysqld
[root@www ~]# sudo systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (exited) since 一 2020-07-06 10:15:10 CST; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9045 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
7月 06 10:15:10 www.a.com systemd[1]: Starting LSB: start and stop MyS....
7月 06 10:15:10 www.a.com mysqld[9045]: Starting MySQL SUCCESS!
7月 06 10:15:10 www.a.com systemd[1]: Started LSB: start and stop MySQL.
7月 06 10:15:10 www.a.com mysqld[9045]: 2020-07-06T02:15:10.792613Z my...s
Hint: Some lines were ellipsized, use -l to show in full.

2、使用init.d  

sudo systemctl status mysqld
[root@www ~]# sudo systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (exited) since 一 2020-07-06 10:15:10 CST; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9045 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
7月 06 10:15:10 www.a.com systemd[1]: Starting LSB: start and stop MyS....
7月 06 10:15:10 www.a.com mysqld[9045]: Starting MySQL SUCCESS!
7月 06 10:15:10 www.a.com systemd[1]: Started LSB: start and stop MySQL.
7月 06 10:15:10 www.a.com mysqld[9045]: 2020-07-06T02:15:10.792613Z my...s
Hint: Some lines were ellipsized, use -l to show in full.
[root@www ~]# sudo /etc/init.d/mysql status
 SUCCESS! MySQL running (8957)

3、如果安装包含systemd支持

[root@www ~]# sudo systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (exited) since 一 2020-07-06 10:15:10 CST; 1min 40s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 9045 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
7月 06 10:15:10 www.a.com systemd[1]: Starting LSB: start and stop MyS....
7月 06 10:15:10 www.a.com mysqld[9045]: Starting MySQL SUCCESS!
7月 06 10:15:10 www.a.com systemd[1]: Started LSB: start and stop MySQL.
7月 06 10:15:10 www.a.com mysqld[9045]: 2020-07-06T02:15:10.792613Z my...s
Hint: Some lines were ellipsized, use -l to show in full.

三、启动及关闭MySQL数据库

1、启动MySQL数据库

cd /usr/local/mysql
support-files/mysql.service start

输出信息如下:

Starting MySQL.SUCCESS!

2、查看MySQL数据库状态

support-files/mysql.service status

输出信息如下:

SUCCESS!MYSQL running

3、配置MySQL数据库的开机自启服务

# 复制mysql.server到/etc/init.d目录下

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

# 使用chkconfig添加mysql服务到开机启动的列表中

chkconfig --add mysqld

现在使用systemctl管理MySQL服务

systemctl status mysqld

4、查看系统配置的开机自启列表

chkconfig  --list

5、关闭MySQL

cd /usr/local/mysql
support-files/mysql.server stop

提示:

关闭MySQL数据库也可以使用mysqladmin命令

mysqladmin -uroot -p密码 shutdown

还有另一种方式关闭MySQL,即使用root用户登录MySQL后,执行shutdown命令

mysql -uroot -p密码
mysql>shutdown



mysql8

人生建议:不要因为嘴硬而失去重要的东西,清醒,知趣,明得失,知进退。

评论

^