Centos设置Mysql开机自启动

将服务文件拷贝到init.d下,并重命名为mysqld

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

赋予可执行权限

chmod +x /etc/init.d/mysqld

将mysql服务加入到开机自启动

[root@localhost support-files]# chkconfig --level 345 mysqld on
# 如果看到mysql的服务,并且3,4,5都是开的话则成功,如果是关,则
[root@localhost support-files]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld          0:关    1:关    2:开    3:开    4:开    5:开    6:关

mysql的相关运行命令

查看服务当前运行状态

[root@localhost support-files]# /etc/init.d/mysqld status
 ERROR! MySQL is not running
[root@localhost support-files]#

启动mysql服务

[root@localhost support-files]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@localhost support-files]# /etc/init.d/mysqld status
 SUCCESS! MySQL running (9271)
[root@localhost support-files]#

停止mysql服务

[root@localhost support-files]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost support-files]#

重启mysql服务

[root@localhost support-files]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL. SUCCESS!
[root@localhost support-files]#

配置修改后重新加载mysql服务

[root@localhost support-files]# /etc/init.d/mysqld reload
 SUCCESS! Reloading service MySQL
[root@localhost support-files]#

systemctl 运行mysql

启动mysql服务

systemctl start mysqld

停止mysql服务

systemctl stop mysqld

mysql的运行状态

[root@localhost ~]# systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
   Active: active (running) since Sat 2021-07-03 17:07:55 CST; 2min 24s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1483 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
    Tasks: 38 (limit: 11362)
   Memory: 439.5M
   CGroup: /system.slice/mysqld.service
           ├─1494 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local>
           └─1721 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugi>

7月 03 17:07:52 localhost.centos8 systemd[1]: Starting LSB: start and stop MySQL...
7月 03 17:07:55 localhost.centos8 mysqld[1483]: Starting MySQL... SUCCESS!
7月 03 17:07:55 localhost.centos8 systemd[1]: Started LSB: start and stop MySQL.
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

融极

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值