解决MySQL因不能创建 PID 导致无法启动的方法
问题描述
MySQL启动报错信息如下:
Startingmysqld(viasystemctl): Jobformysqld.servicefailedbecausethecontrolprocessexitedwitherrorcode.See"systemctlstatusmysqld.service"and"journalctl-xe"fordetails、[FAILED]
根据提示,使用systemctlstatusmysqld.service和journalctl-xe查看服务启动失败的原因。
[root@~]#systemctlstatusmysqld.servicemysqld.service-SYSV:MySQLdatabaseserver.Loaded:loaded(/etc/rc.d/init.d/mysqld)Active:failed(Result:exit-code)sinceWed2016-01-2018:26:57CST;40sagoDocs:man:systemd-sysv-generator(8)Process:2979ExecStart=/etc/rc.d/init.d/mysqldstart(code=exited,status=1/FAILURE)Jan2018:26:56spark01systemd[1]:StartingSYSV:MySQLdatabaseserver….Jan2018:26:57spark01mysqld[2979]:MySQLDaemonfailedtostart.Jan2018:26:57spark01mysqld[2979]:Startingmysqld:[FAILED]Jan2018:26:57spark01systemd[1]:mysqld.service:controlprocessexited,code=exitedstatus=1Jan2018:26:57spark01systemd[1]:FailedtostartSYSV:MySQLdatabaseserver..Jan2018:26:57spark01systemd[1]:Unitmysqld.serviceenteredfailedstate.Jan2018:26:57spark01systemd[1]:mysqld.servicefailed.[root@~]#journalctl-xeUnitsession-2.scopehasbegunstartingup.Jan2018:26:48spark01sshd[2916]:pam_unix(sshd:session):sessionopenedforusersparkby(uid=0)Jan2018:26:52spark01su[2944]:(toroot)sparkonpts/1Jan2018:26:52spark01su[2944]:pam_unix(su-l:session):sessionopenedforuserrootbyspark(uid=1000)Jan2018:26:56spark01polkitd[909]:RegisteredAuthenticationAgentforunix-process:2974:117137(systembusname:1.25Jan2018:26:56spark01systemd[1]:StartingSYSV:MySQLdatabaseserver….—Subject:Unitmysqld.servicehasbegunstart-up—Defined-By:systemd—Support:http://lists.freedesktop.org/mailman/listinfo/systemd-devel——Unitmysqld.servicehasbegunstartingup.Jan2018:26:57spark01mysqld[2979]:MySQLDaemonfailedtostart.Jan2018:26:57spark01mysqld[2979]:Startingmysqld:[FAILED]Jan2018:26:57spark01systemd[1]:mysqld.service:controlprocessexited,code=exitedstatus=1Jan2018:26:57spark01systemd[1]:FailedtostartSYSV:MySQLdatabaseserver..—Subject:Unitmysqld.servicehasfailed—Defined-By:systemd—Support:http://lists.freedesktop.org/mailman/listinfo/systemd-devel——Unitmysqld.servicehasfailed.——Theresultisfailed.Jan2018:26:57spark01systemd[1]:Unitmysqld.serviceenteredfailedstate.Jan2018:26:57spark01systemd[1]:mysqld.servicefailed.Jan2018:26:57spark01polkitd[909]:UnregisteredAuthenticationAgentforunix-process:2974:117137(systembusname:1.
这些信息并不能提供服务启动失败的真正原因。
查看MySQL的告警日志:
2016-01-20T10:00:19.935771Z0[ERROR]/usr/sbin/mysqld:Can'tcreate/writetofile‘/var/run/mysqld/mysqld.pid'(Errcode:2-Nosuchfileordirectory)2016-01-20T10:00:19.935795Z0[ERROR]Can'tstartserver:can'tcreatePIDfile:Nosuchfileordirectory16012018:00:20mysqld_safemysqldfrompidfile/var/run/mysqld/mysqld.pidended
解决办法
MySQL服务在启动的时候,不能创建pid文件。
在终端看一下该目录是否存在,如果不存在,手动创建:
[root@~]#mkdir-p/var/run/mysqld/
再次尝试启动MySQL服务,报错如下:
Startingmysqld(viasystemctl): Jobformysqld.servicefailedbecausethecontrolprocessexitedwitherrorcode.See"systemctlstatusmysqld.service"and"journalctl-xe"fordetails.[FAILED]
查看MySQL的告警日志:
2016-01-20T10:28:37.183387Z0[ERROR]/usr/sbin/mysqld:Can'tcreate/writetofile‘/var/run/mysqld/mysqld.pid'(Errcode:13-Permissiondenied)2016-01-20T10:28:37.183431Z0[ERROR]Can'tstartserver:can'tcreatePIDfile:Permissiondenied16012018:28:37mysqld_safemysqldfrompidfile/var/run/mysqld/mysqld.pidended16012018:32:06mysqld_safeStartingmysqlddaemonwithdatabasesfrom/var/lib/mysql
权限不正确,/var/run/mysqld/的属主和属组还是root,MySQL并不能在其中创建文件后修改该目录的属主和属组
[root@~]#ls-ld/var/run/mysqld/drwxr-xr-x2rootroot40Jan2018:28/var/run/mysqld/ [root@~]#chownmysql.mysql/var/run/mysqld/ [root@~]#/etc/init.d/mysqldstartStartingmysqld(viasystemctl):[OK]
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对毛票票的支持。