+-
首页 专栏 mysql 文章详情
关注作者
关注作者
0
解决Docker MySQL无法被宿主机访问的问题
氷泠 发布于 今天 03:17
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@%
或者创建[email protected]
即可:
create user test@% identified by 'test';
create user [email protected] identified by 'test';
mysql docker
阅读 58 发布于 今天 03:17
赞
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
氷泠
142 声望
10 粉丝
0 条评论
得票 时间
提交评论
氷泠
142 声望
10 粉丝
宣传栏
目录
▲
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@%
或者创建[email protected]
即可:
create user test@% identified by 'test';
create user [email protected] identified by 'test';