centos 让 mysql 随系统启动
[root@VM-8-12-centos ~]# systemctl enable mysql
Failed to execute operation: No such file or directory
systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
解决方案:
# 在 /usr/lib/systemd/system/ 路径下创建 mysql.service
vim /usr/lib/systemd/system/mysql.service
[Unit] Description=MySQL server After=syslog.target network.target [Service] User=mysql Group=mysql Type=forking TimeoutSec=0 #PermissionsStartOnly=true ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize LimitNOFILE = 65535 Restart=on-failure RestartSec=3 RestartPreventExitStatus=1 PrivateTmp=false [Install] WantedBy=multi-user.target
# 重新加载systemctl
systemctl daemon-reload
# 启动|重启|停止mysql
systemctl start mysql
systemctl restart mysql
systemctl stop mysql
# 设置开机启动/不启动mysql服务
systemctl enable mysql
systemctl disable mysql
# 查看状态
systemctl status mysql