启动,关闭,查看MySQL服务Linux
- 查看MySQL服务的状态
[hyj@hadoop102 ~]$ systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2022-07-15 09:33:30 CST; 43min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1370 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 989 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1374 (mysqld)
CGroup: /system.slice/mysqld.service
└─1374 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
7月 15 09:33:26 hadoop102 systemd[1]: Starting MySQL Server...
7月 15 09:33:30 hadoop102 systemd[1]: Started MySQL Server.
- 关闭MySQL服务
[hyj@hadoop102 ~]$ sudo systemctl stop mysqld.service
[hyj@hadoop102 ~]$ systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since 五 2022-07-15 10:22:53 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 5101 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 5079 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 5104 (code=exited, status=0/SUCCESS)
7月 15 10:22:34 hadoop102 systemd[1]: Starting MySQL Server...
7月 15 10:22:35 hadoop102 systemd[1]: Started MySQL Server.
7月 15 10:22:52 hadoop102 systemd[1]: Stopping MySQL Server...
7月 15 10:22:53 hadoop102 systemd[1]: Stopped MySQL Server.
- 启动MySQL服务
[hyj@hadoop102 ~]$ sudo systemctl start mysqld.service
[hyj@hadoop102 ~]$ systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2022-07-15 10:24:00 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 5195 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 5169 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 5198 (mysqld)
CGroup: /system.slice/mysqld.service
└─5198 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
7月 15 10:24:00 hadoop102 systemd[1]: Starting MySQL Server...
7月 15 10:24:00 hadoop102 systemd[1]: Started MySQL Server.
- 设置为MySQL开机自启动服务(建议)
[hyj@hadoop102 ~]$ sudo systemctl enable mysqld.service
- 查看是否已经设置自启动成功
[hyj@hadoop102 ~]$ systemctl list-unit-files | grep mysqld
mysqld.service enabled
mysqld@.service disabled
- 关闭MySQL开机自启动服务
[hyj@hadoop102 ~]$ sudo systemctl disable mysqld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/mysqld.service.
[hyj@hadoop102 ~]$ systemctl list-unit-files | grep mysqld
mysqld.service disabled
mysqld@.service disabled
- 重启MySQL服务
[hyj@hadoop102 hive-3.1.2]$ sudo systemctl restart mysqld.service