centos7.3配置mysql5.6无法启动和重启报错:Job for mysqld.service failed because a timeout was exceeded.

centos7.3配置mysql5.6无法启动和重启报错:Job for mysqld.service failed because a timeout was exceeded.

尝试用root登录MySQL是报错ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

  • 分别使用systemctl status mysqld.service和journalctl -xe查看服务启动失败的原因,但是都不具体
  • 不妨打开MySQL的告警日志cat /var/log/mysqld.log
    这里写图片描述

  • 解决办法
    1.查看当前的my.cnf配置文件 、vim /etc/my.cnf
    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    user=mysq
    symbolic-links=0
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    2.由于编译安装时指定的路径为/opt/data以及mysql_install_db时指定的datadir也为/opt/data,而my.cnf为缺省的路径
    将datadir=/var/lib/mysql改为datadir=/opt/data

  • 保存退出,重启服务
    centos7.3配置mysql5.6无法启动和重启报错:Job for mysqld.service failed because a timeout was exceeded._第1张图片

代码块

报错:

[shaoyun@iz ~]$ systemctl status mysqld.service
● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: activating (start-post) since Tue 2018-09-11 13:34:41 CST; 1min 56s ago
  Process: 23331 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
  Process: 23319 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 23331 (code=exited, status=0/SUCCESS);         : 23332 (mysql-systemd-s)
   CGroup: /system.slice/mysqld.service
           └─control
             ├─23332 /bin/bash /usr/bin/mysql-systemd-start post
             └─23866 sleep 1
[shaoyun@iz ~]$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[shaoyun@iz ~]$ systemctl stop mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
[shaoyun@iz ~]$ systemctl start mysqld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===
Job for mysqld.service failed because a timeout was exceeded. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[shaoyun@iz2ze26or99k31zvb6qo0mz ~]$ systemctl status mysqld.service
● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: activating (start-post) since Tue 2018-09-11 14:11:31 CST; 55s ago
  Process: 30713 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
  Process: 30701 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 30713 (code=exited, status=0/SUCCESS);         : 30714 (mysql-systemd-s)
   CGroup: /system.slice/mysqld.service
           └─control
             ├─30714 /bin/bash /usr/bin/mysql-systemd-start post
             └─30993 sleep 1
[shaoyun@iz ~]$ 

我踩过的坑

1.删除 、/etc/my.cnf文件
2.在my.cnf中添加
server-id=1
expire_logs_days=7
log-bin=mysql-bin
3.操作文件的权限不够
4.卸掉mysql5.6重新装
5.等等
my.cnf的截图
centos7.3配置mysql5.6无法启动和重启报错:Job for mysqld.service failed because a timeout was exceeded._第2张图片


非常感谢下边两位的博客,参考如下:
1:https://blog.csdn.net/leshami/article/details/41801395
2:https://blog.csdn.net/moxiaomomo/article/details/52982938

你可能感兴趣的:(centos7.3配置mysql5.6无法启动和重启报错:Job for mysqld.service failed because a timeout was exceeded.)