CentOS 7下mysqld服务启动失败终极解决方案

启动mysqld服务失败,报错如下:

[[email protected] ~]# 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] ~]# systemctl status mysqld.service
 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.
[[email protected] ~]# journalctl -xe
--
-- 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自带的告警日志,路径一般在/var/log/mysqld.log下面

[[email protected] ~]# tail -200f  /var/log/mysqld.log
2018-12-07 T10: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)
2018-12-07T10:00:19.935795Z 0 [ERROR] Can‘t start server: can‘t create PID file: No such file or directory
181207 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

这个时候我们就明白了,/var/run/mysqld/这个目录不存在,wu,查找下确实没有这个文件。这里我们有两种解决方案

第一种自己创建 /var/run/mysqld/ 这个目录,重新启动mysqld服务

[[email protected] ~]# mkdir -p /var/run/mysqld/
[[email protected] ~]# 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]

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

2018-12-070T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can‘t create/write to file ‘/var/run/mysqld/mysqld.pid‘ (Errcode: 13 - Permission denied)
2018-12-070T10:28:37.183431Z 0 [ERROR] Can‘t start server: can‘t create PID file: Permission denied
181207 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
181207 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

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

[[email protected] ~]# ls -ld /var/run/mysqld/
drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/
[[email protected] ~]# chown mysql.mysql /var/run/mysqld/
[[email protected]~]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]

上面第一种解决方案为临时性的方案,你会发现当虚拟机reboot的话,又会启动不成功,那个目录又不删除了,因此我们修改一下存放mysqld.pid的目录,有两个配置文件

vi  /etc/my.cnf

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/createByhujian/mysqld/mysqld.pid
vi  /etc/init.d/mysqld

get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/createByhujian/mysqld/mysqld.pid"
mypidfile="$result"

红色的部分是我自己在根目录下创建的目录 /createByhujian/mysqld

mkdir -p /createByhujian/mysqld
chown mysql.mysql /createByhujian/mysqld

重启mysqld服务成功,一劳永逸

有什么问题可以下方留言讨论哦!



原文地址:https://www.cnblogs.com/waycx/p/10084447.html

时间: 2024-10-17 09:40:18

CentOS 7下mysqld服务启动失败终极解决方案的相关文章

CentOS 7下MySQL服务启动失败的解决思路

今天,启动MySQL服务器失败,如下所示: [[email protected] ~]# /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 -

阿里云CentOS 7.2 MySQL服务启动失败的解决思路

阿里云 CentOS 7.2 MySQL服务启动失败的解决思路 前言 : 昨天刚刚搭建好的MySQL让老大看了一下,经过测试已经完成任务.但是今天早晨来的时候发现服务器被关了,此时我的心情崩溃的,但是我非常冷静的解决了MySQL问题.如下: 启动MySQL服务器失败,如下所示: [[email protected] ~]# /etc/init.d/mysqld start Starting mysqld (via systemctl):  Job for mysqld.service faile

mysqld服务启动失败, Failed to restart mysqld.service: Unit not found.

-bash-4.2# service mysqld restart Redirecting to /bin/systemctl restart mysqld.serviceFailed to restart mysqld.service: Unit not found. 并不存在 mysqld 的服务, -bash-4.2# -bash-4.2# chkconfig -list -list: unknown option -bash-4.2# chkconfig --list Note: Thi

Linux 下 squid 服务启动失败,无法写入cache.log,Permission denied 解决方法

突然 squid 就启动不了了,打开 squid.out,发现报错: WARNING: Cannot write log file: /var/log/squid/cache.log /var/log/squid/cache.log: Permission denied messages will be sent to 'stderr'. 关键字:Permission denied Permission - 允许,批准 Denied - Deny过去式,拒绝 直接 cd 进入 /var/log/

CentOS下,mysql服务启动失败

mysql服务启动失败,可以使用排除法查找原因: 如果修改了my.cnf后重启mysql服务失败,大多数情况下都是配置文件有错误, 可以通过备份原来的配置文件,然后将配置文件清空,只剩下[mysqld], 使用命令systemctl restart mysqld,如果能成功重启,说明配置文件出问题了, 修改配置文件即可. 如果以上做了之后还是不能重启,这是需要去查看mysql的log文件继续进行问题排查. 原文地址:https://www.cnblogs.com/ryanzheng/p/8496

CentOs 6.6里kdump启动失败的原因

在VMware中新安装了CentOs 6.6,重启系统发现kdump服务启动失败 先来说一下,什么是kdump kdump 是一种先进的基于 kexec 的内核崩溃转储机制.当系统崩溃时,kdump 使用 kexec 启动 到第二个内核.第二个内核通常叫做捕获内核,以很小内存启动以捕获转储镜像.第一个内核保 留了内存的一部分给第二内核启动用.由于 kdump 利用 kexec 启动捕获内核,绕过了 BIOS,所 以第一个内核的内存得以保留.这是内核崩溃转储的本质. 启动失败的原因 查看 /etc

Apache服务启动失败couldn't start errorlog process, unable to open logs

在某用户环境下,Apache服务启动失败,报错信息如下 couldn't start errorlog process unable to open logs Apache是我们的产品组件,未防止日志过大 我们使用了Apache自带的切割滚存日志的组件rotatelogs.exe 在httpd.conf配置如下: ErrorLog "|bin/rotatelogs.exe logs/%Y%m%d%H%M%S_error.log 30M" 只要屏蔽这个设置,就可以正常启动Apache,谷

Exchange 邮件服务器传输服务启动失败

Exchange 邮件服务器传输服务启动失败 事件属性-事件ID 16023 日志名称:          Application 来源:            MSExchangeTransport 日期:            2014/10/1 14:51:50 事件 ID:         16023 任务类别:          配置 级别:            错误 关键字:           经典 用户:            暂缺 计算机:           TCS-MAI

在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作

在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service  操作,而是通过 systemctl 操作. 操作说明如下: 1. 查看 sshd 服务是否启动: 看到上述信息就可以确定是启动了. 2. 如果没有启动,则需要启动该服务:systemctl start sshd.service 3. 重启 sshd 服务:systemctl restart sshd.service 4. 设置服务开启自启:systemctl enable sshd.service