首頁 >運維 >CentOS >centos mysqld啟動失敗怎麼辦

centos mysqld啟動失敗怎麼辦

藏色散人
藏色散人原創
2022-01-28 11:08:074027瀏覽

centos mysqld啟動失敗的解決方法:1、查看服務的日誌;2、修改「/var/run/mysqld/」的屬主和屬群組即可。

centos mysqld啟動失敗怎麼辦

本文操作環境:CentOS 7系統、DELL G3電腦

centos mysqld啟動失敗怎麼辦?

#今天,啟動MySQL伺服器失敗,如下:

[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]

根據提示,分別使用systemctl status mysqld.service和journalctl -xe查看服務啟動失敗的原因

[root@spark01 ~]# systemctl status mysqld.service
?.mysqld.service - SYSV: MySQL database server.
   Loaded: loaded (/etc/rc.d/init.d/mysqld)
   Active: failed (Result: exit-code) since Wed 2016-01-20 18:26:57 CST; 40s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2979 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Jan 20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....
Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld:  [FAILED]
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
Jan 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.
[root@spark01 ~]# journalctl -xe
-- 
-- Unit session-2.scope has begun starting up.
Jan 20 18:26:48 spark01 sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
Jan 20 18:26:52 spark01 su[2944]: (to root) spark on pts/1
Jan 20 18:26:52 spark01 su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
Jan 20 18:26:56 spark01 polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25
Jan 20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has begun starting up.
Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld:  [FAILED]
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
Jan 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.
Jan 20 18:26:57 spark01 polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.

但,可惜的時,這些資訊並不能提供服務啟動失敗的真正原因。

這時候,不妨開啟MySQL的警告日誌,畢竟,只要MySQL服務啟動,警告日誌都會有輸出訊息的,果然

2016-01-20T10:00:19.935771Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2016-01-20T10:00:19.935795Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
160120 18:00:20 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]

依舊報錯,重新檢視警告日誌,有以下輸出

2016-01-20T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2016-01-20T10:28:37.183431Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
160120 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
160120 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

原來,/ var/run/mysqld/的屬主和屬組還是root,mysql並不能在其中創建文件,後修改該目錄的屬主和屬組,啟動OK。

[root@spark01 ~]# ls -ld /var/run/mysqld/
drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/
[root@spark01 ~]# chown mysql.mysql /var/run/mysqld/
[root@spark01 ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl):                           [  OK  ]

 

總結:

以前在玩Kubernetes的時候,常常遇到啟動失敗的情況,根據systemctl的提示,透過systemctl status mysqld.service和journalctl -xe指令查看服務啟動失敗的原因往往不如人意,反而給了一種錯誤的暗示,以為這個跟系統有關。其實,透過查看服務的日誌,往往更能清楚的知道服務啟動失敗的原因。

推薦:《centos使用教學

以上是centos mysqld啟動失敗怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:centos能升級嗎下一篇:centos能升級嗎