V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
zhuzhibin
V2EX  ›  问与答

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

  •  
  •   zhuzhibin · 2020-04-11 13:05:06 +08:00 · 1616 次点击
    这是一个创建于 1680 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本地 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 部署开发环境,其他没研究)

    第 1 条附言  ·  2020-04-11 14:12:24 +08:00
    5 条回复    2023-09-10 21:46:08 +08:00
    zhuzhibin
        1
    zhuzhibin  
    OP
       2020-04-11 13:11:03 +08:00
    🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘🚘
    arjen
        2
    arjen  
       2020-04-11 13:14:28 +08:00 via Android
    看一下 docker-mysql 的 log, docker logs container_id
    zhuzhibin
        3
    zhuzhibin  
    OP
       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
        4
    zhuzhibin  
    OP
       2020-04-11 13:49:21 +08:00
    @arjen 老哥有思路吗 我晚点再 google 一下 看看 so 有没有类似的提问。。
    weiqipeng
        5
    weiqipeng  
       2023-09-10 21:46:08 +08:00
    解决了吗。我用 docker 装的 mysql 自己配置了 my.cnf 也是这情况
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2858 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 09:30 · PVG 17:30 · LAX 01:30 · JFK 04:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.