CentOS7下mysqld服务启动失败终极解决⽅案
启动mysqld服务失败,报错如下:
[root@LCM01GCM01 ~]# 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]
既然有了提⽰,先看下有什么帮助没有
[root@LCM01GCM01 ~]# systemctl status mysqld.service
Loaded: loaded (/etc/rc.d/init.d/mysqld)
Active: failed (Result: exit-code) since Wed 2016-01-2018: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 2018:26:56 spark01 systemd[1]: Starting SYSV: MySQL
Jan 2018:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan 2018:26:57 spark01 mysqld[2979]: Starting mysqld: [FAILED]
Jan 2018:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 2018:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
Jan 2018:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan 2018:26:57 spark01 systemd[1]: mysqld.service failed.
[root@LCM01GCM01 ~]# journalctl -xe
--
-- Unit session-2.scope has begun starting up.
Jan 2018:26:48 spark01 sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
Jan 2018:26:52 spark01 su[2944]: (to root) spark on pts/1
Jan 2018:26:52 spark01 su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
Jan 2018:26:56 spark01 polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25
Jan 2018:26:56 spark01 systemd[1]: Starting SYSV: MySQL
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: /mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has begun starting up.
Jan 2018:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan 2018:26:57 spark01 mysqld[2979]: Starting mysqld: [FAILED]
Jan 2018:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 2018:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: /mailman/listinfo/systemd-devel
--
-- Unit mysqld.service has failed.
--
-- The result is failed.
Jan 2018:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan 2018:26:57 spark01 systemd[1]: mysqld.service failed.
Jan 2018:26:57 spark01 polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.
然⽽,好像这些信息对我们来说并没有什么⽤处,什么守护进程没启动,我们也不能知如何去启动这些,这个时候我们查看⼀下mysql⾃带的告警⽇志,路径⼀般
在/var/log/mysqld.log下⾯
[root@LCM01GCM01 ~]# 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
18120718:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
这个时候我们就明⽩了,/var/run/mysqld/这个⽬录不存在,wu,查下确实没有这个⽂件。这⾥我们有两种解决⽅案
第⼀种⾃⼰创建 /var/run/mysqld/ 这个⽬录,重新启动mysqld服务
[root@LCM01GCM01 ~]# mkdir -p /var/run/mysqld/
[root@LCM01GCM01 ~]# 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)
mysql下载starting the server2018-12-070T10:28:37.183431Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
18120718:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
18120718:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
原来,/var/run/mysqld/的属主和属组还是root,mysql并不能在其中创建⽂件,后修改该⽬录的属主和属组,启动OK。
[root@LCM01GCM01 ~]# ls -ld /var/run/mysqld/
drwxr-xr-x 2 root root 40 Jan 2018:28 /var/run/mysqld/
[root@LCM01GCM01 ~]# sql /var/run/mysqld/
[root@LCM01GCM01~]# service mysqld start
Starting mysqld (via systemctl): [ OK ]
上⾯第⼀种解决⽅案为临时性的⽅案,你会发现当虚拟机reboot的话,⼜会启动不成功,那个⽬录⼜不删除了,因此我们修改⼀下存放mysqld.pid的⽬录,有两个配置⽂件
vi /etc/myf
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
sql /createByhujian/mysqld
service mysqld start
补充:可能会出现还是⽆法启动,查看⽇志
Can't start server: can't create PID file: Permission denied
给前⾯的⼀个⽬录增加权限
chmod +755 /createByhujian
重启mysqld服务成功,⼀劳永逸
有什么问题可以下⽅留⾔讨论哦!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论