問題描述mysql
MySQL 啓動報錯信息以下:sql
1
2
|
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
查看服務啓動失敗的緣由。bash
1
|
[root@ ~]# systemctl status mysqld.servicemysqld.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 agoDocs: 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=1Jan 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@ ~]# journalctl -xeUnit 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/1Jan 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.25Jan 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=1Jan 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.
|
這些信息並不能提供服務啓動失敗的真正緣由。session
查看 MySQL 的告警日誌:ssh
1
|
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 directory160120 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
|
解決辦法學習
MySQL 服務在啓動的時候,不能建立 pid 文件。ui
在終端看一下該目錄是否存在,若是不存在,手動建立:spa
1
|
[root@ ~]
# mkdir -p /var/run/mysqld/
|
再次嘗試啓動 MySQL 服務,報錯以下:.net
1
2
|
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]
|
查看 MySQL 的告警日誌:unix
1
|
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 denied160120 18:28:37 mysqld_safe mysqld from pid
file
/var/run/mysqld/mysqld
.pid ended160120 18:32:06 mysqld_safe Starting mysqld daemon with databases from
/var/lib/mysql
|
權限不正確,/var/run/mysqld/ 的屬主和屬組仍是 root,MySQL 並不能在其中建立文件後修改該目錄的屬主和屬組
1
2
3
|
[root@ ~]
# ls -ld /var/run/mysqld/drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/
[root@ ~]
# chown mysql.mysql /var/run/mysqld/
[root@ ~]
# /etc/init.d/mysqld startStarting mysqld (via systemctl): [ OK ]
|
總結
以上就是這篇文章的所有內容了,但願本文的內容對你們的學習或者工做能帶來必定的幫助,若是有疑問你們能夠留言交流,謝謝你們對腳本之家的支持。