mysql服务无法启动

问题描述

在启动mysql服务的过程中,

sudo service mysql start

抛出异常

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.

通过执行

systemctl status mysql.service

得到提示信息

* mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) (Result: exit-code) since Thu 2019-08-01 16:31:44 CST; 5s ago
  Process: 12773 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
  Process: 12767 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 12773 (code=exited, status=1/FAILURE);         : 12774 (mysql-systemd-s)
   CGroup: /docker/b3c0096db92555e3edf5393809f9e4200974750aa13b4d106583728f20dd8b2c/system.slice/mysql.service
           `-control
             |-12774 /bin/bash /usr/share/mysql/mysql-systemd-start post
             `-12787 sleep 1

分析

结合网上的文章, 有如下几种说法.

  1. 服务器磁盘已满
    排查 : 可以通过df -h查看服务器磁盘使用情况.

  2. mysql配置文件出错
    排查:
    先执行mysql
    如果是配置文件出错,则报错

mysql: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at **line 20**!
mysql: [ERROR] Fatal error in defaults handling. Program aborted!

如果配置文件不出错的话, 则抛出异常

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

这是正常返回, 因为mysql服务没有启动, 所以不可能连接上. 只是用来排查配置文件是否出错.

最终发现引起mysql不能启动的原因在于mysql的配置文件中(个人环境下路径是/etc/mysql/mysql.conf.d/mysqld.cnf) 记录errorlog文件路径(log_error = /var/log/mysql/error.log)不存在.

解决这个问题必须创建该目录并且将相关权限交给mysql:mysql用户.

sudo mkdir -p /var/log/mysql
sudo touch /var/log/mysql/error.log
sudo chown mysql:mysql /var/log/mysql
sudo chown mysql:mysql /var/log/mysql/error.log

References

Job for mysqld.service failed See “systemctl status mysqld.service , journalctl -xe & tail -30 /var/log/mysql/error.log “

Mysql server not starting

MySQL not working after upgrade from 14.04 to 16.04

Centos7 上安装mysql遇上的问题:mysql无法正常启动

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据