在centos7中所有对服务的管理都集中到了systemctl当中,所以服务的启动、关闭、重启、开机启动等等的操作都可以用systemctl。
systemctl对服务的管理都是通过配置文件,配置文件的目录在/usr/lib/systemd/system/,默认情况下没有mysql的配置文件,那就手动添加一个名为mysql.service的配置文件。
在此之前先看一下mysql的安装目录:
whereis mysql
显示
mysql: /usr/lib64/mysql /usr/local/mysql
/usr/local/mysql 这个就是我的安装路径
新建systemctl配置文件
vi /usr/lib/systemd/system/mysql.service
文件内容如下,记着ExecStart里的路径要跟你的mysql安装路径一致(mysqld路径)
1 [Unit] 2 Description=MySQL Server 3 Documentation=man:mysqld(8) 4 Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html 5 After=network.target 6 After=syslog.target 7 8 [Install] 9 WantedBy=multi-user.target 10 11 [Service] 12 User=mysql 13 Group=mysql 14 ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf 15 LimitNOFILE = 5000 16 #Restart=on-failure 17 #RestartPreventExitStatus=1 18 #PrivateTmp=false
最后设置开机启动:
systemctl enable mysql
链接:https://www.jianshu.com/p/2ffa16ca711e