商城首页欢迎来到中国正版软件门户

您的位置:首页 >Docker MySQL无法被宿主机访问如何解决

Docker MySQL无法被宿主机访问如何解决

  发布于2023-05-01 阅读(0)

扫一扫,手机访问

1 问题描述

Docker启动MySQL容器后,创建一个localhost访问的用户:

create user test@localhost identified by 'test';

但是在宿主机中无法通过该用户登录:

mycli -u test

Docker MySQL无法被宿主机访问如何解决

2 原因

Docker中的MySQL创建localhost的用户只能在Docker内部访问,而不能通过外部访问。

至于为什么能在宿主机访问root,是因为默认存在两个root,分别是:

  • root@localhost

  • root@%

Docker MySQL无法被宿主机访问如何解决

test只有一个localhost

Docker MySQL无法被宿主机访问如何解决

3 解决方案

创建test@%或者创建test@172.17.0.1即可:

create user test@% identified by 'test';
create user test@172.17.0.1 identified by 'test';
本文转载于:https://www.yisu.com/zixun/723114.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。

热门关注