阿里云 CentOS 7.2 MySQL服务启动失败的解决思路
前言 :
昨天刚刚搭建好的MySQL让老大看了一下,经过测试已经完成任务。但是今天早晨来的时候发现服务器被关了,此时我的心情崩溃的,但是我非常冷静的解决了MySQL问题。如下:
[root@spark01 ~]# journalctl -xe
但,可惜的时,这些信息并不能提供服务启动失败的真正原因。
这时候,不妨打开MySQL的告警日志,毕竟,只要MySQL服务启动,告警日志都会有输出信息的,果然
2017-06- /usr/sbin/mysqld: Can't create/write to file /var/run/mysqld/mysqld.pid' (Errcode: - No such file or directory) Can't start server: can't create PID file:No such file or directory mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
MySQL服务在启动的时候,不能创建pid文件。
在终端看一下该目录是否存在,果然,不存在。
于是,创建了/var/run/mysqld/目录,重启MySQL服务
[root@spark01 ~]# mkdir -p /var/run/mysqld/
[root@spark01 ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [FAILED]
依旧报错,重新查看告警日志,有以下输出
2017-06-/usr/sbin/mysqld: Can't create/write to file /var/run/mysqld/mysqld.pid' (Errcode: - Permission denied)Can't start server: can't create PID file: Permission denied mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
以上都是临时的配置但是/var/run下的目录重新开机就会还原所以看一下永久配置
vi /usr/lib/systemd/system/mysqld.service
之后重新加载 systemctl daemon-reload