Multiple hostnames and multiple privileges?

南笙酒味 提交于 2019-12-23 01:42:10

问题


I want to map 127.0.0.1 to multiple names instead of the standard way as localhost. so my /etc/hosts file in Ubuntu would have the following entries:

127.0.0.1 localhost
127.0.0.1 localhost:extra1
127.0.0.1 localhost:extra2

Now, in MySQL, I want to have a user named karthick and it should have different privileges.

select user,host from users;

The above statement shows

 karthick localhost:extra1;
 karthick localhost:extra2;

My question:

I am not able to login using

mysql -u karthick -h localhost:extra1 -p

What would be the problem?

Motivation behind the question

I want to login as below

login 1:

mysql -u karthick -h localhost:extra1 -p

login 2:

mysql -u karthick -h localhost:extra2 -p

I want login 1 and login 2 to have different set of privileges... Hope this is possible


回答1:


At the point where mysql receives the connection, all it has to identify the remote system is the IP address. It must then do a "reverse dns" lookup to convert the IP address of the requesting system to a hostname, so that it can look up the hostname in the authorization table. While you can map multiple hostnames to a single IP address, as you have done, there's no way for mysql to know which hostname was originally specified. At that point all it has is 127.0.0.1, and the DNS resolver will return the name 'localhost'. Even if changed that, you could give it only one name, so your scheme won't work.

You can however give your network adapter multiple DIFFERENT IP addresses. I don't know the details of setting this up on Ubuntu, but it should be relatively easy. Then you can set up multiple hostnames each with its own IP that connects back to your system. In your mysql setup specify the IP addresses instead of the hostnames in your GRANT commands to avoid having to mess with rDNS.



来源:https://stackoverflow.com/questions/3540051/multiple-hostnames-and-multiple-privileges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!