CentOS 7下MySQL服务启动失败的快速解决方法
今天,启动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 7下mysql服务启动失败的快速解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: linux find 命令
下一篇: grep命令详解