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