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
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- 无法解决整理冲突 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
