0%

重启mysql报错 ERROR 2002 (HY000)

mysql在非正常关闭后,再次启动时,会报错。客户端也连接不上。

连接时的错误信息:

1
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

尝试重启mysql服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# systemctl status mysqld.service
● mysqld.service - SYSV: MySQL database server.
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since 二 2018-09-25 10:48:39 CST; 1min 28s ago
Docs: man:systemd-sysv-generator(8)
Process: 3351 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

9月 25 10:48:38 deploy systemd[1]: Starting SYSV: MySQL database server....
9月 25 10:48:39 deploy mysqld[3351]: MySQL Daemon failed to start.
9月 25 10:48:39 deploy mysqld[3351]: Starting mysqld: [FAILED]
9月 25 10:48:39 deploy systemd[1]: mysqld.service: control process exited, code=exited status=1
9月 25 10:48:39 deploy systemd[1]: Failed to start SYSV: MySQL database server..
9月 25 10:48:39 deploy systemd[1]: Unit mysqld.service entered failed state.
9月 25 10:48:39 deploy systemd[1]: mysqld.service failed.

查看错误日志

1
2
3
4
5
6
7
8
9
10
# journalctl -xe
9月 25 10:45:47 deploy systemd[1]: mysqld.service: control process exited, code=exited status=1
9月 25 10:45:47 deploy 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.

解决方案

在mysql非正常关闭时,/var/run/mysqld会消失掉。我们查看/var/run/mysqld文件夹是否不存在,如果是,那重新建立此文件夹/var/run/mysqld,并设置权限
chown mysql.mysql /var/run/mysqld

再次重启,正常启动