Host ‘host.docker.internal‘ is not allowed to connect to this MySQL server

836 阅读1分钟

项目背景

Docker Desktop 启动了一个 MySQL 容器, 在使用 Navicat 测试连接的时候, 出现了一个问题 Host ‘host.docker.internal‘ is not allowed to connect to this MySQL server

解决方案

在网上看到的解决方案, 比如说把host改为 % (发现自己的本来就是 % ),还有其他各种方案,都没有解决

  • 查看本机端口状态 netstat -ano

    image.png

    发现 3306 端口被占用;

    重新启动容器, 将宿主机的 3305 端口映射给容器, 解决了!

补充

Windows 查看某一进程, 并杀掉

  1. 进入 Windows 命令窗口, 输入 netstat -ano

  2. 查找某一特定端口, 输入 netstat -ano | findstr "3306"

    image.png

  3. 通过进程ID查找对应的进程名称, 输入tasklist | findstr "7580"

    image.png

  4. 杀死进程, 可直接根据进程的名称或进程的ID杀掉所有的进程, 输入taskkill /f /t /im "7580"

  5. 检查下, 是否真正杀掉, 查找 netstat -ano, 再次查看就发现端口没有被占用了.