当前位置: 首页 > 新闻动态 > 技术教程

Docker MySQL无法被宿主机访问如何解决

作者:WBOY 浏览: 发布日期:2023-05-26
[导读]:1问题描述Docker启动MySQL容器后,创建一个localhost访问的用户:createusertest@localhostidentifiedby'test';但是在宿主机中无法通过该用户登录:mycli-utest2原因在Docker中的MySQL创建localhost的用户只能在Docker内部访问,而不能通过外部访问。至于为什么能在宿主机访问root,是因为默认存在两个root,分别是:root@localhostroot@%而test只有一个loc

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';
免责声明:转载请注明出处:http://sczxchw.cn/news/527056.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!