Today, starting the MySQL server fails as follows:
[Email protected] ~]#/etc/init.d/mysqld startstarting mysqld (via Systemctl): for" systemctl Status Mysqld.service " " Journalctl-xe " for details. [FAILED]
Depending on the prompts, use Systemctl status Mysqld.service and Journalctl-xe to see why the service failed to start
[Email protected] ~]# 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 .- on- - -: -: $CST; 40s ago Docs:Mans: Systemd-sysv-generator (8) Process:2979Execstart=/etc/rc.d/init.d/mysqld Start (code=exited, status=1/FAILURE) Jan - -: -: AboutSpark01 systemd[1]: Starting sysv:mysql database server .... Jan - -: -: $Spark01 mysqld[2979]: MySQL Daemon failed to start. Jan - -: -: $Spark01 mysqld[2979]: Starting mysqld: [Failed]jan - -: -: $Spark01 systemd[1]: Mysqld.service:control process exited, code=exited status=1Jan - -: -: $Spark01 systemd[1]: Failed to start sysv:mysql database server. Jan - -: -: $Spark01 systemd[1]: Unit Mysqld.service entered failed state. Jan - -: -: $Spark01 systemd[1]: Mysqld.service failed.
[Email protected] ~]# Journalctl-xe
----Unit session-2. Scope has begun starting up. Jan - -: -: -Spark01 sshd[2916]: Pam_unix (sshd:session): Session opened forUser Spark by (uid=0) Jan - -: -: theSpark01su[2944]: (to root) spark on pts/1Jan - -: -: theSpark01su[2944]: Pam_unix (su-l:session): Session opened forUser root by Spark (uid= +) Jan - -: -: AboutSpark01 polkitd[909]: Registered authentication Agent forUnix-process:2974:117137(System bus Name:1.25Jan - -: -: AboutSpark01 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 have begun starting up. Jan - -: -: $Spark01 mysqld[2979]: MySQL Daemon failed to start. Jan - -: -: $Spark01 mysqld[2979]: Starting mysqld: [Failed]jan - -: -: $Spark01 systemd[1]: Mysqld.service:control process exited, code=exited status=1Jan - -: -: $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 - -: -: $Spark01 systemd[1]: Unit Mysqld.service entered failed state. Jan - -: -: $Spark01 systemd[1]: Mysqld.service failed. Jan - -: -: $Spark01 polkitd[909]: Unregistered authentication Agent forUnix-process:2974:117137(System bus Name:1.
But, unfortunately, this information does not provide the real reason for the failure of the service to start.
At this time, may wish to open the MySQL alarm log, after all, as long as the MySQL service starts, the alarm log will have output information, sure enough
.- on-20t10:xx: +.935771Z0[ERROR]/usr/sbin/mysqld:can't create/write to file'/var/run/mysqld/mysqld.pid'(Errcode:2-No such file or directory) .- on-20t10:xx: +.935795Z0[ERROR] Can't start Server:can'T create PIDfile: No Suchfileor directory160120 -:xx: -Mysqld_safe mysqld from PIDfile/var/run/mysqld/mysqld.pid Ended
The MySQL service cannot create a PID file when it is started.
At the terminal to see if the directory exists, sure enough, does not exist.
The/var/run/mysqld/directory is created and the MySQL service is restarted
[Email protected] ~]# mkdir-p/var/run/mysqld/
[[email protected] ~]#/etc/init.d/mysqld start
Starting mysqld (via Systemctl): for "systemctl status mysqld.service"" journalctl-xe" for details. [FAILED]
Still error, re-check the alarm log, with the following output
.- on-20t10: -:Panax Notoginseng.183387Z0[ERROR]/usr/sbin/mysqld:can't create/write to file'/var/run/mysqld/mysqld.pid'(Errcode:13-permission denied) .- on-20t10: -:Panax Notoginseng.183431Z0[ERROR] Can't start Server:can'T create PIDfile: Permission denied160120 -: -:Panax NotoginsengMysqld_safe mysqld from PIDfile/var/run/mysqld/Mysqld.pid ended160120 -: +: .Mysqld_safe starting mysqld daemon with databases From/var/lib/mysql
It turns out that the owner and the/var/run/mysqld/group or root,mysql can not create a file in it, and then modify the owner and owner of the directory, start OK.
ls -ld /var/run/mysqld/drwxr2:/ var/run/mysqld/chown mysql.mysql/var/run/mysqld/~]#/etc/init.d/mysqld Startstarting mysqld (via Systemctl): [ OK ]
Summarize:
In the past, when playing kubernetes, often encountered boot failure, according to Systemctl, systemctl status Mysqld.service and Journalctl-xe command to see the cause of service startup failure is often not satisfactory, Instead, it gives a false hint that this is related to the system. In fact, by looking at the log of the service, it is often clearer to know why the service failed to start.
The solution to the startup failure of the MySQL service under CentOS 7