•The pattern ’%’  means “any host”  and is least specific. 

•The empty string ’’  also means “any host”  but sorts after ’%’ . 

Non-TCP (socket file, named pipe, and shared memory) connections are treated as local connections and match a host part of localhost  if there are any such accounts, or host parts with wildcards that match localhost  otherwise (for example, local% , l% , % ). 

Rows with the same Host  value are ordered with the most-specific User  values first. A blank User  value means “any user”  and is least specific, so for rows with the same Host  value, nonanonymous users sort before anonymous users. 

For rows with equally-specific Host  and User  values, the order is nondeterministic. 

To see how this works, suppose that the user  table looks like this: 

+-----------+----------+- | Host | User | ... +-----------+----------+- | % | root | ... | % | jeffrey | ... | localhost | root | ... | localhost | | ... +-----------+----------+- 

When the server reads the table into memory, it sorts the rows using the rules just described. The result after sorting looks like this: 

+-----------+----------+- | Host | User | ... +-----------+----------+- | localhost | root | ... | localhost | | ... | % | jeffrey | ... | % | root | ... +-----------+----------+- 

When a client attempts to connect, the server looks through the sorted rows and uses the first match found. For a connection from localhost  by jeffrey , two of the rows from the table match: the one with Host  and User  values of ’localhost’  and ’’ , and the one with values of ’%’  and ’jeffrey’ . The ’localhost’  row appears first in sorted order, so that is the one the server uses. 

Here is another example. Suppose that the user  table looks like this: 

+----------------+----------+- | Host | User | ... +----------------+----------+- | % | jeffrey | ... | h1.example.net | | ... +----------------+----------+- 

The sorted table looks like this: 

+----------------+----------+- | Host | User | ... +----------------+----------+- | h1.example.net | | ... | % | jeffrey | ... +----------------+----------+- 

The first row matches a connection by any user from h1.example.net , whereas the second row matches a connection by jeffrey  from any host. 

