概述
在重启阿里的CentOS7服务器后,重启MySQL 出现错误
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@djaljdw ~]# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2019-08-22 14:42:39 CST; 1min 25s ago
Docs: man:systemd-sysv-generator(8)
Process: 2427 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
Aug 22 14:42:37 izw91diu854rguz systemd[1]: Starting SYSV: MySQL database server....
Aug 22 14:42:39 izw91diu854rguz mysqld[2427]: MySQL Daemon failed to start.
Aug 22 14:42:39 izw91diu854rguz mysqld[2427]: Starting mysqld: [FAILED]
Aug 22 14:42:39 izw91diu854rguz systemd[1]: mysqld.service: control process exited, code=exited status=1
Aug 22 14:42:39 izw91diu854rguz systemd[1]: Failed to start SYSV: MySQL database server..
Aug 22 14:42:39 izw91diu854rguz systemd[1]: Unit mysqld.service entered failed state.
Aug 22 14:42:39 izw91diu854rguz systemd[1]: mysqld.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
[root@djaljdw ~]# 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)
14:44:42 InnoDB: Waiting for the background threads to start
14:44:43 InnoDB: 5.5.59 started; log sequence number 1940403
14:44:43 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
14:44:43 [Note] - '0.0.0.0' resolves to '0.0.0.0';
14:44:43 [Note] Server socket created on IP: '0.0.0.0'.
2019-10-26T00:24:02.962361Z 0 [Note] Server socket created on IP: '::'.
2019-10-26T00:24:02.964343Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/opt/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2019-10-26T00:24:02.964366Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
问题找到了:不能创建PID文件:没有这样的文件或目录
于是去查看,果然没有文件夹
[root@djaljdw ~]# cd /var/run
[root@djaljdw ~]# mkdir mysqld
[root@djaljdw ~]# cd mysqld
[root@djaljdw ~]# touch mysqld.pid
重启服务还是报错
于是又查看日志
2019-10-26T00:24:02.962361Z 0 [Note] Server socket created on IP: '::'.
2019-10-26T00:24:02.964343Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/opt/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2019-10-26T00:24:02.964366Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
发现:无法创建PID文件:权限被拒绝
解决办法:
修改 /var/run/mysqld/权限为mysql
[root@djaljdw ~]# chown -R mysql /var/run/mysqld
[root@djaljdw ~]# chgrp -R mysql /var/run/mysqld
[root@djaljdw ~]# chmod 777 /var/run/mysqld
注意:并没有解决问题; 再次重启还是不能启动mysql5.7; 最终的解决方案,注意我的文件位置/opt/mysqld/ 启动一直失败.
也授权,也修改用户组,都没有效果.
修改/etc/my.cnf配置文件:
pid-file=/var/lib/mysql/mysqld.pid
有的说在root下创建目录, 修改权限,都不能从根本上解决问题;
就那么简单,修改my.cnf配置文件的pid-file的位置./var/lib/mysql/ 这个位置也不需要配置什么权限.
最后加上开机自启动systemctl enable mysqld.service
最后
以上就是魔幻母鸡为你收集整理的CentOS7下MySQL服务启动失败原因及解决方法的全部内容,希望文章能够帮你解决CentOS7下MySQL服务启动失败原因及解决方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复