[英]Can't use 127.0.0.1 to connect mysql server docker container, but can use IP?
In my personal PC, there's a docker mysql container binding with port 3306. It works well. 在我的个人PC中,有一个与端口3306绑定的docker mysql容器。它运行良好。 I can connect the mysql server in this container over another PC.
我可以通过另一台PC在此容器中连接mysql服务器。
sh$ mysql -hxxx.xxx.xxx.110 -uroot -p
In the host PC, I can connect the container by this way: 在主机PC中,我可以通过以下方式连接容器:
sh$ mysql -hxxx.xxx.xxx.110 -uroot -p
But when I try to connect the container to 127.0.0.1, it fails: 但是,当我尝试将容器连接到127.0.0.1时,它失败了:
sh$ mysql -uroot -p
Known: 已知:
In the container, I can connect the mysql server by: 在容器中,我可以通过以下方式连接mysql服务器:
sh$ mysql -uroot -p
there's nothing wrong with the password 密码没有问题
Meanwhile, I can connect 127.0.0.1:6376 over the host to the redis container.... 同时,我可以将主机上的127.0.0.1:6376连接到redis容器。
I'm only speculating, but the Docker container likely has its own [pseudo] network interface. 我只是在推测,但是Docker容器可能具有自己的[伪]网络接口。 But you're trying to connect over the host's loopback interface.
但是您正在尝试通过主机的环回接口进行连接。 Those are two separate networks.
那是两个独立的网络。
Remember, 127.0.0.1 is not just a special IP — it's an IP assigned by a separate network interface. 请记住,127.0.0.1不仅是一个特殊的IP —它是由单独的网络接口分配的IP。
You can configure Docker to share the host's network stack; 您可以将Docker配置为共享主机的网络堆栈。 perhaps that would be best here.
也许那是最好的。
Please try follow steps: 1.login mysql with ip and use "select host,user,password from mysql.user;" 请尝试按照以下步骤操作:1.使用ip登录mysql并使用“从mysql.user中选择主机,用户,密码;” to check 127.0.0.1 exists or not in command result;
检查命令结果中是否存在127.0.0.1;
2.if not please execute grant command and ensure 127.0.0.1 has privileges,then tray login again. 2.如果没有,请执行Grant命令并确保127.0.0.1拥有特权,然后再次登录托盘。
grant all on *.* to root@'127.0.0.1' identified by 'root';
flush privileges;
You're going to want to check your my.cnf
for the bind-address
configuration: 您将要检查
my.cnf
的bind-address
配置:
#
# File: my.cnf
#
[mysqld]
bind-address = 192.168.1.100
In good practice and depending on your use-case, this should be 127.0.0.1
. 在良好实践中,根据您的用例,此值应为
127.0.0.1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.