[!]求助本地 MySQL 连不上了提示: ERROR 2002 (HY000): Can't connect to local MySQL server through socket

2020-04-11 13:05:06 +08:00
 zhuzhibin

本地 MySQL 是 docker-composer 统一部署的,之前一直都是正常使用,但是一次 CPU 爆满电脑意外关机重启后,发现本地连不上 MySQL 了,远程的 ssh 是正常的,看报错是 mysql 连接套接字问题,于是我做了下面的尝试:

1.重启 MySQL 容器服务 2.重建 docker-composer 所有镜像 3.尝试 exec 到 MySQL 容器 bash 连接

结果发现还是连不上,有几处比较关键的报错提示,我这里贴一下:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
2013 - Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"

比较奇怪的一点,我发现 mysql 一直反复重启,一直在 Restarting 这个状态

docker_mysql_1           docker-entrypoint.sh mysqld      Restarting

各位大佬们帮帮手吗 我太难顶了鸭( ps:docker 小白,仅仅是喜欢 docker 部署开发环境,其他没研究)

1644 次点击
所在节点    问与答
5 条回复
zhuzhibin
2020-04-11 13:11:03 +08:00
🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘
arjen
2020-04-11 13:14:28 +08:00
看一下 docker-mysql 的 log, docker logs container_id
zhuzhibin
2020-04-11 13:47:21 +08:00
@arjen

```
➜ docker docker logs 8c769a2e2ac4
2020-04-11 04:42:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:42:24+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:42:24+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:42:36+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:42:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:42:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:42:49+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:42:51+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:42:51+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:03+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:43:03+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:12+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:43:12+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:19+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:21+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:43:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:32+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-04-11 04:43:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.
2020-04-11 04:43:45+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian10 started.

```
zhuzhibin
2020-04-11 13:49:21 +08:00
@arjen 老哥有思路吗 我晚点再 google 一下 看看 so 有没有类似的提问。。
weiqipeng
2023-09-10 21:46:08 +08:00
解决了吗。我用 docker 装的 mysql 自己配置了 my.cnf 也是这情况

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/661418

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX