1. 程式人生 > >解決Centos7.4無法啟動mysql異常

解決Centos7.4無法啟動mysql異常

重啟前好好的系統;重啟後,web頁面打不開。查tomcat日誌發現償試連線資料庫3次失敗。登入伺服器,shell命令也不能正常連線。檢視系統程序沒有mysql。

啟動mysql服務報錯

[[email protected] init.d]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

[
[email protected]
init.d]# 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]
根據提示檢查服務狀態
[[email protected] init.d]# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2018-07-06 13:43:52 CST; 1min 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3886 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Jul 06 13:43:51 zhangcool-cooler01 systemd[1]: Starting SYSV: MySQL database server....
Jul 06 13:43:52 zhangcool-cooler01 mysqld[3886]: MySQL Daemon failed to start.
Jul 06 13:43:52 zhangcool-cooler01 mysqld[3886]: Starting mysqld:  [FAILED]
Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: Failed to start SYSV: MySQL database server..
Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: Unit mysqld.service entered failed state.
Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: mysqld.service failed.

[
[email protected]
init.d]# journalctl -xe Jul 06 13:42:58 zhangcool-cooler01 polkitd[477]: Unregistered Authentication Agent for unix-process:3597:8111728 (system bus name :1.355, object path Jul 06 13:43:51 zhangcool-cooler01 polkitd[477]: Registered Authentication Agent for unix-process:3880:8117203 (system bus name :1.356 [/usr/bin/pktt Jul 06 13:43:51 zhangcool-cooler01 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. Jul 06 13:43:52 zhangcool-cooler01 mysqld[3886]: MySQL Daemon failed to start. Jul 06 13:43:52 zhangcool-cooler01 mysqld[3886]: Starting mysqld:  [FAILED] Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: mysqld.service: control process exited, code=exited status=1 Jul 06 13:43:52 zhangcool-cooler01 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. Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: Unit mysqld.service entered failed state. Jul 06 13:43:52 zhangcool-cooler01 systemd[1]: mysqld.service failed. Jul 06 13:43:52 zhangcool-cooler01 polkitd[477]: Unregistered Authentication Agent for unix-process:3880:8117203 (system bus name :1.356, object path  

檢視mysql日誌,分析mysql啟動過程有何異常

[[email protected] init.d]# vi /var/log/mysqld.log
2018-07-06T05:43:52.466691Z 0 [Note] Server socket created on IP: '::'.
2018-07-06T05:43:52.469258Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2018-07-06T05:43:52.469270Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory

原來/var/run/mysqld目錄不存在,所在mysqld.pid無法建立

建立目錄/var/run/mysqld,並授權,再次啟動mysql成功

[[email protected] webapps]# mkdir -p /var/run/mysqld
[[email protected] webapps]# ll /var/run/
drwxr-xr-x.  2 root root   40 Jul  6 13:54 mysqld
[[email protected] webapps]# chown -R mysql.mysql /var/run/mysqld
[[email protected] webapps]# ll /var/run/
drwxr-xr-x.  2 mysql mysql   40 Jul  6 13:54 mysqld