经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » MySQL » 查看文章
CentOS7下MySQL服务启动失败原因及解决方法
来源:cnblogs  作者:别咬吸管  时间:2019/8/23 8:42:21  对本文有异议

在重启阿里的CentOS7服务器后,重启MySQL 出现错误

  1. 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.
  2. [FAILED]

按照提示查看错误信息

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

  1. mysqld.service - SYSV: MySQL database server.
  2. Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
  3. Active: failed (Result: exit-code) since Thu 2019-08-22 14:42:39 CST; 1min 25s ago
  4. Docs: man:systemd-sysv-generator(8)
  5. Process: 2427 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)
  6. Aug 22 14:42:37 izw91diu854rguz systemd[1]: Starting SYSV: MySQL database server....
  7. Aug 22 14:42:39 izw91diu854rguz mysqld[2427]: MySQL Daemon failed to start.
  8. Aug 22 14:42:39 izw91diu854rguz mysqld[2427]: Starting mysqld: [FAILED]
  9. Aug 22 14:42:39 izw91diu854rguz systemd[1]: mysqld.service: control process exited, code=exited status=1
  10. Aug 22 14:42:39 izw91diu854rguz systemd[1]: Failed to start SYSV: MySQL database server..
  11. Aug 22 14:42:39 izw91diu854rguz systemd[1]: Unit mysqld.service entered failed state.
  12. Aug 22 14:42:39 izw91diu854rguz systemd[1]: mysqld.service failed.
  13. Hint: Some lines were ellipsized, use -l to show in full.

[root@djaljdw ~]#  journalctl -xe

  1. --
  2. -- Unit session-2.scope has begun starting up.
  3. Jan 20 18:26:48 spark01 sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
  4. Jan 20 18:26:52 spark01 su[2944]: (to root) spark on pts/1
  5. Jan 20 18:26:52 spark01 su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
  6. Jan 20 18:26:56 spark01 polkitd[909]: Registered Authentication Agent for unix-process:2974:117137
  7. (system bus name :1.25
  8. Jan 20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....
  9. -- Subject: Unit mysqld.service has begun start-up
  10. -- Defined-By: systemd
  11. -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  12. --
  13. -- Unit mysqld.service has begun starting up.
  14. Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
  15. Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld: [FAILED]
  16. Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
  17. Jan 20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
  18. -- Subject: Unit mysqld.service has failed
  19. -- Defined-By: systemd
  20. -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  21. --
  22. -- Unit mysqld.service has failed.
  23. --
  24. -- The result is failed.
  25. Jan 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
  26. Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.
  27. Jan 20 18:26:57 spark01 polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137
  28. (system bus name :1.

发现里面并没有提供有用的错误信息

所以去查看mysql日志信息(/var/log/mysqld.log)

  1. 190822 14:44:42 [Note] Plugin 'FEDERATED' is disabled.
  2. 190822 14:44:42 InnoDB: The InnoDB memory heap is disabled
  3. 190822 14:44:42 InnoDB: Mutexes and rw_locks use GCC atomic builtins
  4. 190822 14:44:42 InnoDB: Compressed tables use zlib 1.2.3
  5. 190822 14:44:42 InnoDB: Using Linux native AIO
  6. 190822 14:44:42 InnoDB: Initializing buffer pool, size = 128.0M
  7. 190822 14:44:42 InnoDB: Completed initialization of buffer pool
  8. 190822 14:44:42 InnoDB: highest supported file format is Barracuda.
  9. InnoDB: The log sequence number in ibdata files does not match
  10. InnoDB: the log sequence number in the ib_logfiles!
  11. 190822 14:44:42 InnoDB: Database was not shut down normally!
  12. InnoDB: Starting crash recovery.
  13. InnoDB: Reading tablespace information from the .ibd files...
  14. InnoDB: Restoring possible half-written data pages from the doublewrite
  15. InnoDB: buffer...
  16. 190822 14:44:42 InnoDB: Waiting for the background threads to start
  17. 190822 14:44:43 InnoDB: 5.5.59 started; log sequence number 1940403
  18. 190822 14:44:43 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
  19. 190822 14:44:43 [Note] - '0.0.0.0' resolves to '0.0.0.0';
  20. 190822 14:44:43 [Note] Server socket created on IP: '0.0.0.0'.
  21. 190822 14:44:43 [ERROR] /usr/libexec/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
  22. 190822 14:44:43 [ERROR] Can't start server: can't create PID file: No such file or directory

问题找到了:不能创建PID文件:没有这样的文件或目录

于是去查看,果然没有文件夹

[root@djaljdw ~]#  cd /var/run
[root@djaljdw ~]#  mkdir mysqld
[root@djaljdw ~]#  cd mysqld
[root@djaljdw ~]#  touch mysqld.pid
重启服务还是报错
于是又查看日志
  1. 190822 14:56:51 [Note] Plugin 'FEDERATED' is disabled.
  2. 190822 14:56:51 InnoDB: The InnoDB memory heap is disabled
  3. 190822 14:56:51 InnoDB: Mutexes and rw_locks use GCC atomic builtins
  4. 190822 14:56:51 InnoDB: Compressed tables use zlib 1.2.3
  5. 190822 14:56:51 InnoDB: Using Linux native AIO
  6. 190822 14:56:51 InnoDB: Initializing buffer pool, size = 128.0M
  7. 190822 14:56:51 InnoDB: Completed initialization of buffer pool
  8. 190822 14:56:51 InnoDB: highest supported file format is Barracuda.
  9. InnoDB: The log sequence number in ibdata files does not match
  10. InnoDB: the log sequence number in the ib_logfiles!
  11. 190822 14:56:51 InnoDB: Database was not shut down normally!
  12. InnoDB: Starting crash recovery.
  13. InnoDB: Reading tablespace information from the .ibd files...
  14. InnoDB: Restoring possible half-written data pages from the doublewrite
  15. InnoDB: buffer...
  16. 190822 14:56:51 InnoDB: Waiting for the background threads to start
  17. 190822 14:56:52 InnoDB: 5.5.59 started; log sequence number 1940403
  18. 190822 14:56:52 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
  19. 190822 14:56:52 [Note] - '0.0.0.0' resolves to '0.0.0.0';
  20. 190822 14:56:52 [Note] Server socket created on IP: '0.0.0.0'.
  21. 190822 14:56:52 [ERROR] /usr/libexec/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13)
  22. 190822 14:56:52 [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

重启服务完美解决

tip:看日志是解决问题的一个很好的办法!

 

原文链接:http://www.cnblogs.com/bieyaoxiguan/p/11394556.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号