阿里云服务器ECS Linux MySQL 常见无法启动或启动异常的解决方法(1)
阿里云服务器ECS Linux MySQL 常见无法启动或启动异常的情况比较多,凯华互联小编分几期说明解决方法,今天第一期先说说不能创建 PID 导致无法启动,错误日志:Can't start server: can't create PID file: No such file or directory
问题描述
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]
根据提示,使用 systemctl status mysqld.service 和 journalctl -xe 查看服务启动失败的原因。
-
[root@ ~]# systemctl status mysqld.servicemysqld.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 agoDocs: 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=1Jan 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.[root@ ~]# journalctl -xeUnit 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/1Jan 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.25Jan 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=1Jan 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 的告警日志:
-
2016-01-20T10: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)2016-01-20T10:00:19.935795Z 0 [ERROR] Can’t start server: can’t create PID file: No such file or directory160120 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
解决办法
MySQL 服务在启动的时候,不能创建 pid 文件。
在终端看一下该目录是否存在,如果不存在,手动创建:
[root@ ~]# mkdir -p /var/run/mysqld/
再次尝试启动 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]
查看 MySQL 的告警日志:
-
2016-01-20T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can’t create/write to file ‘/var/run/mysqld/mysqld.pid’ (Errcode: 13 - Permission denied)2016-01-20T10:28:37.183431Z 0 [ERROR] Can’t start server: can’t create PID file: Permission denied160120 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended160120 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
权限不正确,/var/run/mysqld/ 的属主和属组还是 root,MySQL 并不能在其中创建文件后修改该目录的属主和属组,
-
[root@
~]# ls -ld /var/run/mysqld/drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/[root@ ~]# chown mysql.mysql /var/run/mysqld/[root@ ~]# /etc/init.d/mysqld startStarting mysqld (via systemctl): [ OK ]
以上就是阿里云服务器ECS Linux 文件系统异常导致服务器启动失败的相关内容。阿里云代理商凯铧互联提供阿里云服务器/企业邮箱等产品的代购服务,同样的品质,更多贴心的服务,更实惠的价格。 阿里云代理商凯铧互联会为您提供一对一专业全面的技术服务,同时还能为您提供阿里云其他产品购买的专属折扣优惠。通过凯铧互联购买可以获得折上折优惠!若您需要帮助可以直接联系我方客服,阿里云代理商凯铧互联专业技术团队为您提供全面便捷专业的7x24技术服务。 电话专线:136-5130-9831,QQ:3398234753。
为什么选择我们:北京凯铧互联科技有限公司(简称凯铧互联)由多名前阿里云资深技术专家创立,核心员工来自阿里巴巴、腾讯等,作为阿里云,腾讯云百度云,金山云重要的合作伙伴,专注于为企业用户提供云计算及云计算的解决方案。总部设在北京,并在内蒙设有办事处。做为一家综合性方案商,凯铧互联向各行业用户提供基于云计算的各种解决方案。为用户获得优质服务的同时,秉承"专业规划、周到服务"的服务理念,根据用户的实际情况,充分考虑各种网络资源的特点及功效,为用户量身定做一套适合于其实际应用需求的网络应用方案。帮助用户利用互联网的力量展开新的营销方式,并大大缩短了项目实施周期,获得用户的一致好评。