docker启动mysql容器后,创建一个localhost访问的用户:
create user test@localhost identified by 'test';
但是在宿主机中无法通过该用户登录:
mycli -u test
在Docker中的MySQL创建localhost的用户只能在Docker内部访问,而不能通过外部访问。
至于为什么能在宿主机访问root,是因为默认存在两个root,分别是:
root@localhost
root@%
而test只有一个localhost:
创建test@%或者创建test@172.17.0.1即可:
create user test@% identified by 'test'; create user test@172.17.0.1 identified by 'test';
以上就是Docker MySQL无法被宿主机访问如何解决的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号