MySQL因不能创建 PID 导致无法启动的解决办法-阿里云开发者社区

开发者社区> sr_zhang> 正文

MySQL因不能创建 PID 导致无法启动的解决办法

简介: 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 查看服务启动失败的原因。
+关注继续查看

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 查看服务启动失败的原因。阿里云2018年10月 优惠信息汇总



[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 的告警日志: 

 [ERROR] /usr/sbin/mysqld: Can't create/write to file ‘/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)

[ERROR] Can't start server: can't create PID file: No such file or directory

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 的告警日志:

 [ERROR] /usr/sbin/mysqld: Can't create/write to file ‘/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)2018-09-20T10:28:37.183431Z 0 [ERROR] Can't start server: can't create PID file: Permission denied180920 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 ]





版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
MySQL 中两张表主键自增时,Java 后端组成树形结构的解决办法
当需要将两张不同表的数据进行合并处理,并且两张表的主键均为自增,主键同是数字。这时候需要区分的、不同的表进行取值,可以使其中一张表的主键为负数,即-1,-2,-3。 当需要把取出来的两张表分别再存进数据库时,要将之前取值是负数的主键转为正数,而转为正数的方式也很简单,也就是负负得正,即(-(...
1151 0
SqlServer数据库(可疑)解决办法4种
亲自试过,可行!!!!! SqlServer数据库(可疑)解决办法4种   重启服务--------------------------------------------------日志文件丢了,建一个日志文件------------------------------------------...
923 0
Unit mysql.service failed to load: No such file or directory的解决办法
Failed to issue method call: Unit mysql.service failed to load: No such file or directory的解决办法 1、软件环境: OpenSUSE 13.
2185 0
sql server 2008 评估期已过期解决办法 + vs2008破解(转)
SQL2008破解: 以前在虚拟机中安装了SQL Server 2008简体中文版用于做实验,当时由于一时偷懒,没有输入企业版的序列号,而是安装的企业试用版(Enterprise Evaluation),能够试用180天,半年的时间我想对一个虚拟机来说还是足够了。
1808 0
weblogic启动失败:Could not obtain the localhost address 解决办法
linux下weblogic启动如果出现这个错误,多半是hosts文件不对 1、先输入hostname,查看本机计算机名(比如:server123) 2、sudo vi /etc/hosts 编辑hosts文件,在最后加一行 127.
970 0
远程连接MySQL数据库提示:ERROR 1130 (HY000)的解决办法
远程连接MySQL数据库提示:ERROR 1130的解决办法   >>>>         
1022 0
+关注
17
文章
94
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载