博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CentOS 7下mysqld服务启动失败终极解决方案
阅读量:6191 次
发布时间:2019-06-21

本文共 5182 字,大约阅读时间需要 17 分钟。

启动mysqld服务失败,报错如下:

[root@LCM01GCM01 ~]# service 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]

既然有了提示,先看下有什么帮助没有

[root@LCM01GCM01 ~]# systemctl status mysqld.service 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=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@LCM01GCM01 ~]# 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/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自带的告警日志,路径一般在/var/log/mysqld.log下面

[root@LCM01GCM01 ~]# tail -200f  /var/log/mysqld.log2018-12-07 T10: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)2018-12-07T10:00:19.935795Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory181207 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

这个时候我们就明白了,/var/run/mysqld/这个目录不存在,wu,查找下确实没有这个文件。这里我们有两种解决方案

第一种自己创建 /var/run/mysqld/ 这个目录,重新启动mysqld服务

[root@LCM01GCM01 ~]# mkdir -p /var/run/mysqld/[root@LCM01GCM01 ~]# service 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]

依旧报错,重新查看告警日志,有以下输出

2018-12-070T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)2018-12-070T10:28:37.183431Z 0 [ERROR] Can't start server: can't create PID file: Permission denied181207 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended181207 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

原来,/var/run/mysqld/的属主和属组还是root,mysql并不能在其中创建文件,后修改该目录的属主和属组,启动OK。

[root@LCM01GCM01 ~]# ls -ld /var/run/mysqld/drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/[root@LCM01GCM01 ~]# chown mysql.mysql /var/run/mysqld/[root@LCM01GCM01~]# service mysqld startStarting mysqld (via systemctl):                           [  OK  ]

上面第一种解决方案为临时性的方案,你会发现当虚拟机reboot的话,又会启动不成功,那个目录又不删除了,因此我们修改一下存放mysqld.pid的目录,有两个配置文件

vi  /etc/my.cnfsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0log-error=/var/log/mysqld.logpid-file=/createByhujian/mysqld/mysqld.pid
vi  /etc/init.d/mysqldget_mysql_option mysqld datadir "/var/lib/mysql"datadir="$result"get_mysql_option mysqld socket "$datadir/mysql.sock"socketfile="$result"get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"errlogfile="$result"get_mysql_option mysqld_safe pid-file "/createByhujian/mysqld/mysqld.pid"mypidfile="$result"

红色的部分是我自己在根目录下创建的目录 /createByhujian/mysqld

mkdir -p /createByhujian/mysqldchown mysql.mysql /createByhujian/mysqld

 

重启mysqld服务成功,一劳永逸

有什么问题可以下方留言讨论哦!

 

 

 

转载于:https://www.cnblogs.com/waycx/p/10084447.html

你可能感兴趣的文章
精读《async/await 是把双刃剑》
查看>>
Android P 应用兼容常见错误及建议
查看>>
[译]Android 生命周期备忘录 — 第一部分:单一 Activities
查看>>
Android内存泄露浅析
查看>>
【Android】仿斗鱼滑动拼图验证码控件
查看>>
让 UIWebview 拥有超强的图片处理能力
查看>>
异步社区本周(5.14-5.20)半价电子书
查看>>
Xcode 高级调试技巧
查看>>
理解DDoS防护本质:基于资源较量和规则过滤的智能化系统
查看>>
js 中基础数据结构数组去重问题
查看>>
Android Gradle(一)为什么现在要用Gradle?
查看>>
Python 简单入门指北(试读版)
查看>>
技术变化那么快,程序员如何做到不被淘汰?
查看>>
虚拟DOM总结
查看>>
阿里资深技术专家总结:要怎样努力才可以成为公司主力架构师
查看>>
k-means 聚类算法
查看>>
我们来说一说TCP神奇的40ms
查看>>
基于AOP的MVP框架(一)GoMVP的使用
查看>>
拜托,面试别再问我回文链表了!!!(leetcode 234)
查看>>
iOS冰与火之歌 – UAF and Kernel Pwn
查看>>