我的 docker-compose.yaml:
version: '3'
services:
mysql57:
container_name: mysql57
image: mysql:5.7.29
ports:
- "3306:3306"
volumes:
- $HOME/:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
我的数据库配置文件:
nemo:
default_cluster: local
default_database: my_local
clusters:
local:
databases:
my_local:
user: me
password: me
host: 127.0.0.1 # localhost works for me
mysql:
mysql> SHOW GRANTS;
+---------------------------------------------------------------------+
| Grants for me@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'me'@'localhost' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `my_local`.* TO 'me'@'localhost' |
| GRANT ALL PRIVILEGES ON `my_config`.* TO 'me'@'localhost' |
+---------------------------------------------------------------------+
我的 MAC 设置:
% cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
我有错误:
{Operation:"get config DB connection", Message:"Database error: Cannot connect to database: Error 1045: Access denied for user 'me'@'localhost' (using password: YES). (init master config for local, my_config)"}
但是如果db config文件中的host改成localhost
,错误就会消失。
但是如果db config文件中的host改成127.0.0.1
,就可以看到上面的错误。