解决MySQL因不能创建 PID 导致无法启动的方法
程序员文章站
2022-11-24 19:10:44
问题描述
mysql 启动报错信息如下:
starting mysqld (via systemctl):
job for mysqld.service f...
问题描述
mysql 启动报错信息如下:
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@ ~]# 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.
这些信息并不能提供服务启动失败的真正原因。
查看 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 directory160120 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
解决办法
mysql 服务在启动的时候,不能创建 pid 文件。
在终端看一下该目录是否存在,如果不存在,手动创建:
[root@ ~]# mkdir -p /var/run/mysqld/
再次尝试启动 mysql 服务,报错如下:
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 的告警日志:
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 并不能在其中创建文件后修改该目录的属主和属组
[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 ]
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。
上一篇: 虽然觉得大哥实在太可怜了但是还是好想笑
下一篇: 一起学Android之GridView