首页 帮助中心 香港云服务器 CentOS 7下MySQL服务启动失败的解决思路
CentOS 7下MySQL服务启动失败的解决思路
时间 : 2023-05-10 11:07:50 编辑 : 华纳云 阅读量 : 193

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

[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.

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

[root@spark01 ~]# 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)

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.

[root@spark01 ~]# journalctl -xe

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

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

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服务

[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.

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

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。

[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命令查看服务启动失败的原因往往并不如人意,反而给了一种错误的暗示,以为这个跟系统有关。其实,通过查看服务的日志,往往更能清晰的知道服务启动失败的原因。

华纳云 推荐文章
Linux进程间共享内存实现方法 windows系统开启防火墙后如何放行远程端口 Centos8更改运行级别具体方法 windows使用nginx实现网站负载均衡测试实例 如何在Ubuntu Linux防火墙中检查防火墙状态? Ubuntu系统释放磁盘空间具体方法 centos7服务器系统如何配置静态ip CentOS 7虚拟机克隆的网络问题怎么解决 宝塔面板设置禁止通过IP直接访问网站防止恶意解析 Linux 创建用户并配置SSH免密登录
客服咨询
7*24小时技术支持
技术支持
渠道支持