1 问题描述
2 原因
3 解决方案
1 问题描述Docker启动MySQL容器后,创建一个localhost访问的用户:
create user test@localhost identified by 'test';
但是在宿主机中无法通过该用户登录:
mycli -u test

在Docker中的MySQL创建localhost的用户只能在Docker内部访问,而不能通过外部访问。
至于为什么能在宿主机访问root,是因为默认存在两个root,分别是:
root@localhost
root@%

而test只有一个localhost:

创建test@%或者创建test@172.17.0.1即可:
create user test@% identified by 'test';
create user test@172.17.0.1 identified by 'test';
到此这篇关于Docker MySQL无法被宿主机访问的问题解决的文章就介绍到这了,更多相关Docker MySQL无法被宿主机访问内容请搜索易知道(ezd.cc)以前的文章或继续浏览下面的相关文章希望大家以后多多支持易知道(ezd.cc)!