MySQL 自启动时报错can't create PID file: No such file or directory

系统版本:Red Hat Enterprise Linux Server release 7.0
MySQL版本:5.7.16-1.el6.x86_64
安装MySQL后,设置好了开机自启动。
但是重启服务器后,MySQL并没有启动,查看日志如下:

2018-04-13T06:27:24.608793Z 0 [ERROR] /usr/sbin/mysqld: Can’t create/write to file ‘/var/run/mysqld/mysqld.pid’ (Errcode: 2 - No such file or directory)
2018-04-13T06:27:24.608833Z 0 [ERROR] Can’t start server: can’t create PID file: No such file or directory
2018-04-13T06:27:24.638771Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

错误截图
尝试解决:
# mkdir -p /var/run/mysqld/
# chown -R mysql:mysql /var/run/mysqld/
# systemctl restart mysqld.service
成功启动了MySQL,貌似解决了问题,其实不然。
查阅了MySQL官方文档:https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html
仔细甄别了下我的安装包是:5.7.16-1.el6.x86_64,而RHEL7对应的安装包应该是:5.7.16-1.el7.x86_64
且要为MySQL添加或更改systemd选项:
修改项
至此问题根本原因找到,且解决。

猜你喜欢

转载自blog.csdn.net/cy309173854/article/details/79929468