How is the host for a MySQL user evaluated by the database? My server tries to connect to the database from myhostname but fails even though I’ve set the hostname for that server in /etc/hostname It does work when I use an IP though.
The user was created like so:
GRANT ALL ON db.* TO 'dude'@'myhostname';
The MySQL error will tell you the hostname the server machine thinks your user is connecting from. Depending on DNS settings, this may or may not be the hostname your client thinks is assigned to itself. The name as seen from the server is the one you need to set in your
GRANTstatement.(Which is logical. Suppose I know that the server gives privileges to host Alice. I have host Bob. Since it’s my host, I can change its name to Alice. If just doing this granted me Alice’s privileges, the whole
GRANTscheme would be completely insecure! What happens is that my host thinks it’s Alice, but the server sees my IP, asks the DNS “Who is this?” and receives “He’s Bob”. I still can steal Alice’s privileges, but I need to compromise the DNS records somehow)In a pinch, add the client IP and hostname to the server
/etc/hostsfile. This is a hack, however, and proper DNS setting is the way to go: a forgottenhostshack might cost you a long time of head scratching a few months down the road.