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';