not able to connect to mysql docker from local(无法从本地连接到 mysql docker)
问题描述
我正在尝试从 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
如果我尝试使用 localhost
和 127.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
这篇关于无法从本地连接到 mysql docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法从本地连接到 mysql docker


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01