1 问题描述
docker启动
mysql容器后,创建一个
localhost访问的用户:
create user test@localhost identified by 'test';
但是在宿主机中无法通过该用户登录:
mycli -u test

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

而
test只有一个
localhost:

3 解决方案
创建
test@%或者创建
test@172.17.0.1即可:
create user test@% identified by 'test'; create user test@172.17.0.1 identified by 'test';
