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

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

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

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

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

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

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

手把手教你解决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 成功启动!

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

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

原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/252317.html

(0)
上一篇 2022年5月4日
下一篇 2022年5月4日

相关推荐

发表回复

登录后才能评论