关于mysql:解决Docker-MySQL无法被宿主机访问的问题

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

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理