原创

记一次mysql启动失败的解决方法

1. 尝试启动

systemctl start mysqld.service

响应:

Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details

2.查看原因

结合前面的这句话,分别使用systemctl status mysqld.servicejournalctl -xe查看信息:

systemctl status mysqld.service

响应:

 mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Tue 2020-05-05 15:41:33 CST; 7s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 9842 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 9817 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: Failed to start MySQL Server.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: Unit mysqld.service entered failed state.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: mysqld.service failed.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: mysqld.service holdoff time over, scheduling restart.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: Stopped MySQL Server.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: start request repeated too quickly for mysqld.service
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: Failed to start MySQL Server.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: Unit mysqld.service entered failed state.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: mysqld.service failed.
journalctl -xe

响应:

May 05 15:41:32 izhp3h5r7harxw0tpm3pp9z systemd[1]: Starting MySQL 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.
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: 2020-05-05T07:41:33.261261Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Ple
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: 2020-05-05T07:41:33.265011Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.27) starting as process 9845 .
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: 2020-05-05T07:41:33.276777Z 0 [ERROR] Could not open file '/var/log/mysqld.log' for error loggin
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: 2020-05-05T07:41:33.276817Z 0 [ERROR] Aborting
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: 2020-05-05T07:41:33.276892Z 0 [Note] Binlog end
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: 2020-05-05T07:41:33.277043Z 0 [Note] /usr/sbin/mysqld: Shutdown complete
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: mysqld.service: control process exited, code=exited status=1
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z mysqld[9842]: Initialization of mysqld failed: 0
May 05 15:41:33 izhp3h5r7harxw0tpm3pp9z systemd[1]: Failed to start MySQL Server.
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.

3.解决问题

可以看到[ERROR] 级别的信息:Could not open file '/var/log/mysqld.log' for error loggin 没有权限给写日志

直接到该目录查看该文件的权限,然后查看mysql进程的权限。给该文件赋予相同的权限即可;

cd /var/log
chown -R mysql:mysql mysqld.log

然后再执行启动命令以及查看状态命令:

systemctl start mysqld.service
systemctl status mysqld.service

响应:

mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-05-05 15:48:49 CST; 1min 0s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 22330 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 22286 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 22333 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─22333 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

May 05 15:48:47 izhp3h5r7harxw0tpm3pp9z systemd[1]: Starting MySQL Server...
May 05 15:48:49 izhp3h5r7harxw0tpm3pp9z systemd[1]: Started MySQL Server.

如果哪里有不对的地方,欢迎大佬留言指出!谢谢~ (っ•̀ω•́)っ✎⁾⁾

正文到此结束
本文目录