阿裡雲 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