简体   繁体   中英

Unable to connect to mysql from host virtual machine

$ mysql -u testuser -h 192.168.57.5 -p

Access denied for user 'root'@'192.168.57.1' (using password: YES)

On virtual guest i had already given permissions to mysql user with below command:

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

My Quetion is why i need to grant permissions to root@192.168.57.1?

My IP address of virtual machine is 192.168.57.5.

In MySQL Config:

bind-address = 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.

But i have to grant permissions to 192.168.57.1 in MySQL Server.

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.

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

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

Client Machine IP : 192.168.57.5

In order to access MySQL from Client machine. I have to provide Grant permissions for Host Manager network IP address instead of virtual machine ip address.

That's why below works:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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