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