0
点赞
收藏
分享

微信扫一扫

MySQL实现开机自启

文档课题:MySQL实现开机自启.
数据库:MySQL 8.0.27

1、自启动脚本
Linux中通过编写启动脚本实现MySQL开机自启.
[mysql@leo-827mgr-slave01 ~]$ vi start_mysql.sh
添加如下内容:
#!/bin/bash
# chkconfig: 2345 10 90 
# description: Auto-starts mysql
# /etc/init.d/start_mysql.sh
/opt/mysql-8.0.27-linux-glibc2.17-x86_64-minimal/bin/mysqld_safe --defaults-file=/home/mysql/etc/my.cnf &

说明:若未添加蓝色高亮部分,在执行chkconfig –add时会报错” service start_mysql.sh does not support chkconfig”.

2、脚本文件处理
--修改sudoers文件,使mysql可执行root指令.
[root@leo-827mgr-slave01 ~]# vi /etc/sudoers
添加如下:
mysql   ALL=(ALL)       ALL

--复制启动脚本到系统指定位置,以便系统能够找到并执行它.
[mysql@leo-827mgr-slave01 ~]$ sudo cp /home/mysql/start_mysql.sh /etc/init.d/
[mysql@leo-827mgr-slave01 ~]$ sudo chkconfig --add start_mysql.sh
[mysql@leo-827mgr-slave01 ~]$ sudo chkconfig --level 2345 start_mysql.sh on
[mysql@leo-827mgr-slave01 ~]$ sudo chmod +x /etc/init.d/start_mysql.sh

--确认脚本自启动情况
[mysql@leo-827mgr-slave01 ~]$ sudo chkconfig --list | grep mysql
[sudo] password for mysql: 

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

start_mysql.sh  0:off   1:off   2:on    3:on    4:on    5:on    6:off

3、验证自启动情况
[root@leo-827mgr-slave01 ~]# reboot

Last login: Sat Sep 30 14:22:53 2023 from bogon
[root@leo-827mgr-slave01 ~]# ps -ef|grep mysql
root        790      1  0 18:09 ?        00:00:00 /bin/sh /opt/mysql-8.0.27-linux-glibc2.17-x86_64-minimal/bin/mysqld_safe --defaults-file=/home/mysql/etc/my.cnf
mysql      1076    790  1 18:09 ?        00:00:04 /opt/mysql-8.0.27-linux-glibc2.17-x86_64-minimal/bin/mysqld --defaults-file=/home/mysql/etc/my.cnf --basedir=/opt/mysql --datadir=/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/opt/logs/mysql_error.log --pid-file=/mysql/data/mysql.pid --socket=/mysql/data/mysql.sock --port=3306
root       3174   3135  0 18:14 pts/0    00:00:00 grep --color=auto mysql

说明:如上所示,MySQL服务自动启动.

举报

相关推荐

0 条评论