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

2次阅读

共计 355 个字符,预计需要花费 1 分钟才能阅读完成。

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';
正文完
 0