无法从本地连接到mysql docker [英] not able to connect to mysql docker from local

查看:474
本文介绍了无法从本地连接到mysql docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从docker image连接到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

这篇关于无法从本地连接到mysql docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆