无法从本地连接到 mysql docker

2021-12-07 00:00:00 docker mysql

我正在尝试从 docker 镜像连接到 mysql 数据库.但是它抛出错误.

I am trying to connect to mysql database from docker image. However it's throwing errors.

以下是我正在使用的 docker 镜像.https://hub.docker.com/_/mysql/

following is the docker image I am using. https://hub.docker.com/_/mysql/

以下是我用来运行 docker 镜像的命令.

And following is the command I have used to run the docker image.

docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=password -d mysql:8

以下是docker ps命令的输出

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                              NAMES
9f35d2e39476        mysql:8             "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp

如果我使用 docker inspect 检查 IP 并 ping 该 IP,则显示 IP 无法访问.

if I check the IP using docker inspect and ping that IP, it shows IP is not reachable.

docker inspect 9f35d2e39476 | grep -i ipaddress

如果我尝试使用 localhost127.0.0.1 连接,我会收到以下错误.

And if i try to connect using localhost and 127.0.0.1 I am getting following error.

无法加载身份验证插件caching_sha2_password".

Unable to load authentication plugin 'caching_sha2_password'.

推荐答案

首先,请注意您使用的是不稳定的软件,因此版本和意外行为之间可能会发生重大变化.

First of all, be aware that you're using non stable software, so there can be major changes between releases and unexpected behaviour.

编辑:不再开发,稳定版本于 2018 年 4 月 19 日发布

Edit: Is not in development anymore, stable release launched April 19, 2018

其次,你不能直接ping你的容器,它在其他网,但是你可以很容易地使用另一个容器来ping他.

Secondly, you cannot ping directly your container, it's in other net, but you can easily use another container to ping him.

mysql 8 使用 caching_sha2_password 作为默认的认证插件而不是 mysql_native_password.更多信息在这里.

mysql 8 uses caching_sha2_password as the default authentication plugin instead of mysql_native_password. More info here.

许多 mysql 驱动程序还没有添加对 caching_sha2_password 的支持.

Many mysql drivers haven't added support for caching_sha2_password yet.

如果您遇到问题,可以使用以下内容更改为旧的身份验证插件:

If you're having problems with it, you can change to the old authentication plugin with something like this:

docker run -p 3306:3306 --name mysql_80 -e MYSQL_ROOT_PASSWORD=password -d mysql:8 mysqld --default-authentication-plugin=mysql_native_password

相关文章