I needed an user to be able to log in on our MySQL server 5.6 from machine foobarhost, IP

Therefore I created a user 'joe'@'foobarhost' but he was unable to log in. I had to create an user 'joe'@'' and this time worked fine.

My question: how does MySQL handle hostnames vs IP addresses concerning users?

MySQL sorts the user table before checking for a match, using IP addresses and hostnames as the most-specific values to match to. However, the docs do not specify what takes precedence - hostname or IP. Does MySQL attempt a hostname resolution and, if it fails, performs a check on the IP?

What is the recommended usage for the user table: specify only IP addresses, hostnames, or both (as I did in the example above)?


I had this problem before, and after long investigation I found out sometimes MySQL can not resolve any issue related to DNS by default, so I did the following: edited hosts file ( can be found under Linux /etc/hosts, for Windows C:\Windows\System32\drivers\etc\hosts) and added ip and hostname for the client machine,in your example its foobarhost

then save and close ( note Windows will require reboot before taking any effect), you may need to add the following parameters --skip-name-resolve and\or --skip-host-cache .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.