centos mysqld启动失败怎么处理

centos mysqld启动失败的解决办法:1、查看服务的日志;2、修改“/var/run/mysqld/”的属主和属组即可。

centos mysqld启动失败怎么处理插图

本文操作环境:CentOS 7系统、DELL G3电脑

centos mysqld启动失败怎么办?

今天,启动MySQL服务器失败,如下所示:

1

2

3

[root@spark01 ~]# /etc/init.d/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]

根据提示,分别使用systemctl status mysqld.service和journalctl -xe查看服务启动失败的原因

1

[root@spark01 ~]# systemctl status mysqld.service

1

2

3

4

5

6

7

8

9

10

11

12

?.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)

Jan 20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....

Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.

Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld:  [FAILED]

Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1

Jan 20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..

Jan 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.

Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.

1

[root@spark01 ~]# journalctl -xe

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

--

-- Unit session-2.scope has begun starting up.

Jan 20 18:26:48 spark01 sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)

Jan 20 18:26:52 spark01 su[2944]: (to root) spark on pts/1

Jan 20 18:26:52 spark01 su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)

Jan 20 18:26:56 spark01 polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25

Jan 20 18:26:56 spark01 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.

Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.

Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld:  [FAILED]

Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1

Jan 20 18:26:57 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 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.

Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.

Jan 20 18:26:57 spark01 polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.

但,可惜的时,这些信息并不能提供服务启动失败的真正原因。

这时候,不妨打开MySQL的告警日志,毕竟,只要MySQL服务启动,告警日志都会有输出信息的,果然

1

2

3

2016-01-20T10:00:19.935771Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)

2016-01-20T10:00:19.935795Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory

160120 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

MySQL服务在启动的时候,不能创建pid文件。

在终端看一下该目录是否存在,果然,不存在。

于是,创建了/var/run/mysqld/目录,重启MySQL服务

1

2

3

4

[root@spark01 ~]# mkdir -p /var/run/mysqld/

[root@spark01 ~]# /etc/init.d/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]

依旧报错,重新查看告警日志,有以下输出

1

2

3

4

2016-01-20T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)

2016-01-20T10:28:37.183431Z 0 [ERROR] Can't start server: can't create PID file: Permission denied

160120 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

160120 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

原来,/var/run/mysqld/的属主和属组还是root,mysql并不能在其中创建文件,后修改该目录的属主和属组,启动OK。

1

2

3

4

5

[root@spark01 ~]# ls -ld /var/run/mysqld/

drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/

[root@spark01 ~]# chown mysql.mysql /var/run/mysqld/

[root@spark01 ~]# /etc/init.d/mysqld start

Starting mysqld (via systemctl):                           [  OK  ]

总结:

以前在玩Kubernetes的时候,常遇到启动失败的情况,根据systemctl的提示,通过systemctl status mysqld.service和journalctl -xe命令查看服务启动失败的原因往往并不如人意,反而给了一种错误的暗示,以为这个跟系统有关。其实,通过查看服务的日志,往往更能清晰的知道服务启动失败的原因。

版权声明:本文采用知识共享 署名4.0国际许可协议BY-NC-SA 进行授权
文章作者:jiuhucn
文章链接:https://www.jiuhucn.com/2022/03/19/1731.html
免责声明:本站为资源分享站,所有资源信息均来自网络,您必须在下载后的24个小时之内从您的电脑中彻底删除上述内容;版权争议与本站无关,所有资源仅供学习参考研究目的,如果您访问和下载此文件,表示您同意只将此文件用于参考、学习而非其他用途,否则一切后果请您自行承担,如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
本站为非盈利性站点,并不贩卖软件,不存在任何商业目的及用途,网站会员捐赠是您喜欢本站而产生的赞助支持行为,仅为维持服务器的开支与维护,全凭自愿无任何强求。

THE END
分享
二维码
打赏
< <上一篇
下一篇>>