简体   繁体   English

无法从主机虚拟机连接到 mysql

[英]Unable to connect to mysql from host virtual machine

$ mysql -u testuser -h 192.168.57.5 -p $ mysql -u testuser -h 192.168.57.5 -p

Access denied for user 'root'@'192.168.57.1' (using password: YES)用户 'root'@'192.168.57.1​​' 访问被拒绝(使用密码:YES)

On virtual guest i had already given permissions to mysql user with below command:在虚拟来宾上,我已经使用以下命令向 mysql 用户授予了权限:

GRANT ALL ON DB.* TO root@192.168.57.5 IDENTIFIED BY 'password'; GRANT ALL ON DB.* TO root@192.168.57.5 IDENTIFIED BY 'password';

But above is not working.但以上是行不通的。

Below Solution is working:下面的解决方案正在工作:

GRANT ALL ON DB.* TO root@192.168.57.1 IDENTIFIED BY 'password'; GRANT ALL ON DB.* TO root@192.168.57.1​​ IDENTIFIED BY 'password';

My Quetion is why i need to grant permissions to root@192.168.57.1?我的问题是为什么我需要授予 root@192.168.57.1​​ 权限?

My IP address of virtual machine is 192.168.57.5.我的虚拟机IP地址是192.168.57.5。

In MySQL Config:在 MySQL 配置中:

bind-address = 192.168.57.5绑定地址 = 192.168.57.5

I can access my virtual machine apache server with ip 192.168.57.5 and mysql server too with 192.168.57.5.我可以使用 ip 192.168.57.5 访问我的虚拟机 apache 服务器,也可以使用 192.168.57.5 访问 mysql 服务器。

But i have to grant permissions to 192.168.57.1 in MySQL Server.但是我必须在 MySQL 服务器中授予 192.168.57.1​​ 的权限。

I'm sure this has been answered many times but here it goes one more time...我相信这个问题已经回答过很多次了,但这里再重复一次......

When you grant privileges, you grant them to the user that is connecting .当您授予权限时,您将它们授予正在连接的用户。 What you are doing above is granting access to your MySQL server.您在上面所做的是授予对MySQL服务器的访问权限。

GRANT ALL ON DB.* TO root@192.168.57.5 IDENTIFIED BY 'password'; GRANT ALL ON DB.* TO root@192.168.57.5 IDENTIFIED BY 'password';

Means grant all to user root who's IP is 192.168.57.5表示将所有权限授予IP 为192.168.57.5 的用户root

When you grant access to your client that wishes to use the server, it magically works.当您授予希望使用服务器的客户端访问权限时,它会神奇地工作。

In My vitual box:在我的虚拟框中:

Host Manager IP: 192.168.57.1 and主机管理器 IP:192.168.57.1​​ 和

Client Machine IP : 192.168.57.5客户端机器 IP : 192.168.57.5

In order to access MySQL from Client machine.为了从客户端机器访问 MySQL。 I have to provide Grant permissions for Host Manager network IP address instead of virtual machine ip address.我必须为 Host Manager 网络 IP 地址而不是虚拟机 IP 地址提供授予权限。

That's why below works:这就是为什么下面的作品:

GRANT ALL ON DB.* TO root@192.168.57.1 IDENTIFIED BY 'password'; GRANT ALL ON DB.* TO root@192.168.57.1​​ IDENTIFIED BY 'password';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM