标签:mysql
centos7 系统中编译安装mysql或者mariab启动不了服务 报错
错误如下:
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@Allen ~]#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 Allen systemd[1]: Starting SYSV: MySQL database server....
Jan 20 18:26:57 Allen mysqld[2979]: MySQL Daemon failed to start.
Jan 20 18:26:57 Allen mysqld[2979]: Starting mysqld: [FAILED]
Jan 20 18:26:57 Allen systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 20 18:26:57 Allen systemd[1]: Failed to start SYSV: MySQL database server..
Jan 20 18:26:57 Allen systemd[1]: Unit mysqld.service entered failed state.
Jan 20 18:26:57 Allen systemd[1]: mysqld.service failed.
[root@Allen ~]# journalctl -xe
--
-- Unit session-2.scope has begun starting up.
Jan 20 18:26:48 Allen sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
Jan 20 18:26:52 Allen su[2944]: (to root) spark on pts/1
Jan 20 18:26:52 Allen su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
Jan 20 18:26:56 Allen polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25
Jan 20 18:26:56 Allen 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 Allen mysqld[2979]: MySQL Daemon failed to start.
Jan 20 18:26:57 Allen mysqld[2979]: Starting mysqld: [FAILED]
Jan 20 18:26:57 Allen systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 20 18:26:57 Allen 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 Allen systemd[1]: Unit mysqld.service entered failed state.
Jan 20 18:26:57 Allen systemd[1]: mysqld.service failed.
Jan 20 18:26:57 Allen polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.
可惜的是以上这些信息并不能提供服务启动失败的真正原因。没有找到有什么可用的信息
查看日志文件。因为只要MySQL服务启动,告警日志都会有输出信息的
[root@Allen ~]# tail /var/log/mysqld.log
2017-07-17T10: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)
2017-07-17T10:00:19.935795Z 0 [ERROR] Can‘t start server: can‘t create PID file: No such file or directory
170717 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
mysql启动的时候不能创建pid文件
终端查看了一下 目录不存在
创建了/var/run/mysqld/目录,重启MySQL服务
[root@Allen ~]#mkdir -p /var/run/mysqld/
[root@Allen ~]#/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.
[FAILED]
查看日志:
[root@Allen ~]#tailf /var/log/mysqld.log
2017-07-17T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can‘t create/write to file ‘/var/run/mysqld/mysqld.pid‘ (Errcode: 13 - Permission denied)
2017-07-17T10:28:37.183431Z 0 [ERROR] Can‘t start server: can‘t create PID file: Permission denied
170717 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
170717 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
可以看到/var/run/mysqld/的属主和属组还是root,mysql并不能在其中创建文件,后修改该目录的属主和属组。重启数据库
[root@Allen ~]#vll -d /var/run/mysqld/
drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/
[root@Allen ~]#chown mysql:mysql /var/run/mysqld/
[root@Allen ~]#/etc/init.d/mysqld restart
Starting mysqld (via systemctl): [ OK ]
最后可用ps -ef | grep mysql 或者ss -anptlu | grep 3306查看服务是否运行或端口否起来
本文出自 “12252646” 博客,请务必保留此出处http://12262646.blog.51cto.com/12252646/1948274
标签:mysql
原文地址:http://12262646.blog.51cto.com/12252646/1948274