手把手教你解决MySQL服务启动失败排查并修复恢复启动问题

SQL herman 359浏览
公告:“业余草”微信公众号提供免费CSDN下载服务(只下Java资源),关注业余草微信公众号,添加作者微信:codedq,发送下载链接帮助你免费下载!
本博客日IP超过2000,PV 3000 左右,急需赞助商。
极客时间所有课程通过我的二维码购买后返现24元微信红包,请加博主新的微信号:codedq,之前的微信号好友位已满,备注:返现
受密码保护的文章请关注“业余草”公众号,回复关键字“0”获得密码
所有面试题(java、前端、数据库、springboot等)一网打尽,请关注文末小程序
视频教程免费领

手把手教你解决MySQL服务启动失败排查并修复恢复启动问题

上次帮一个网友远程解决了一个问题,直接打赏了我,今天又一个网友打赏了我。

事件起因是这样的,网友在执行一条 SQL 时,提示错误。网友搜索得出答案,需要设置 sql_mode,她百度一番,然后进行了修改。

ONLY_FULL_GROUP_BY

重启服务后,发现 MySQL 服务无法启动。

我问网友遇到了什么错误,对方给我发来了一个截图。

mysql 启动失败,发生错误

由于截图太小,看不全内容,因此进行了远程手把手教程。

我首先执行 mysql 的启动命令:

service mysql 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查看服务启动失败的原因”。

于是,我先执行了 systemctl status mysqld.service 命令。

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)

 systemd[1]: Starting SYSV: MySQL database server....
 xttblog mysqld[2979]: MySQL Daemon failed to start.
 xttblog mysqld[2979]: Starting mysqld:  [FAILED]
 xttblog systemd[1]: mysqld.service: control process exited, code=exited status=1
 xttblog systemd[1]: Failed to start SYSV: MySQL database server..
 xttblog systemd[1]: Unit mysqld.service entered failed state.
 xttblog systemd[1]: mysqld.service failed.

上面这段错误日志,我没看出具体的错误原因。于是,就又执行了 journalctl -xe 命令。

-- Unit session-2.scope has begun starting up.
xttblog sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
xttblog su[2944]: (to root) spark on pts/1
xttblog su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
xttblog polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25
xttblog 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.
xttblog mysqld[2979]: MySQL Daemon failed to start.
xttblog mysqld[2979]: Starting mysqld:  [FAILED]
xttblog systemd[1]: mysqld.service: control process exited, code=exited status=1
xttblog systemd[1]: Failed to start SYSV: MySQL database server..
[ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
-- 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.
xttblog systemd[1]: Unit mysqld.service entered failed state.
xttblog systemd[1]: mysqld.service failed.
xttblog polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.

上面的日志中,有一段很明显的内容。

“[ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory”

抓住重点信息,我在 /var/log/mysql/error.log 目录下,新建了 error.log 文件,并给上 755 权限。

然后,我再次启动 mysql 服务,service mysql start 成功启动!

业余草公众号

最后,欢迎关注我的个人微信公众号:业余草(yyucao)!可加作者微信号1:xmtxtt(5000人已满),微信号2:xttblog(5000人已满),微信号3:codedq(超3800)。备注:“1”,添加博主微信拉你进微信群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作也可添加作者微信进行联系!

本文原文出处:业余草: » 手把手教你解决MySQL服务启动失败排查并修复恢复启动问题