Troubleshooting MySQL access privileges issues: Q & A

MySQL access privilegesIn this blog, I will provide answers to the Q & A for the Troubleshooting MySQL Access Privileges Issues webinar.

First, I want to thank everybody for attending the February 23 webinar. The recording and slides for the webinar are available here. Below is the list of your questions that I wasn’t able to answer during the webinar, with responses:

Q: Should the root@localhost user be given ALL privileges or Super privileges? Does All include Super privileges also?

A: Yes, you should have a user with all privileges. Better if this user has access from localhost only. ALL  includes SUPER.

Q: We have users who connect via a laptop that get dynamic IP addresses, so granting access with a server name is an easier way to manage these users. Can I grant access to a MySQL database with a hostname as opposed to an ipaddress? For example “” as opposed to “myname@”?  Is the host cache/performance_schema required for this?

A: Yes, you can.

But it looks like I was not clear about host cache. Host cache is an internal structure that is always available and contains answers from DNS server. You cannot enable or disable it. Until version 5.6, you also could not control it. For example, if the cache got corrupted the only thing you could do is to restart the server. Version 5.6 the table HOST_CACHE was introduced to Performance Schema. With this table you can examine the content of the host cache and truncate it if needed.

Q: If there are multiple entries in the user table that match the connecting user (e.g., with wildcards, hostname, and IP), what rules does MySQL use to select which is used for authentication?  Does it try multiple ones until it gets a password match?

A: Not, mysqld does not try to hack your passwords. Instead it sorts the user table by name and host in descending order as I showed on slide #37 (page 110). Then it takes the first matching row. So if you created users foo@somehost, foo@some% and foo@, and you connect as foo from somehost, mysqld first checks the user name and then chooses the first matching row foo@somehost. If you instead connect as foo from someotherhost, mysqld chooses  foo@some%. An IP-based host is chosen if either mysqld started with option skip-networking or if  points to a host whose name does not start with “some”.

Mixing IP-based and name-based hosts is dangerous in situations when the same host can be resolved as somehost or In this case, if something goes wrong with the host cache or DNS server, the wrong entry from the user table can be chosen. For example, if you initially had three hosts: uniquehost (which resolves as, somehost (which resolves as and someothershost (which resolves as Now you decided to re-locate uniquehost to a machine with IP and use IP for the host with name someyetanotherhost. In this case, the clients from the machine with IP will be treated as foo@some%, which isn’t what you want.

To demonstrate this issue, I created two users and granted two different privileges to them:

Now I modified my /etc/hosts  file and pointed address  to name Thinkie:

Now, if I connect as sveta both Thinkie and are resolved to the same host:

Now I modified the  /etc/hosts  file and pointed Thinkie  back to  ( localhost):

But host still resolves to Thinkie:

The reason for this is a stalled host cache, which can be easily observable with Performance Schema: