Rectangle 27 0

Using % for host when creating a MySQL user?


mysql -h192.168.0.1 -uuser -p
user@'%'
Note
Rectangle 27 0

Using % for host when creating a MySQL user?


Actually there is, 'localhost' is special in mysql, it means a connection over a unix socket (or named pipes on windows I believe) as opposed to a TCP/IP socket. using % as the host does not include 'localhost'

Not only does "localhost" connect via the local socket, 127.0.0.1 (which doesn't use the socket) won't match % but localhost instead, too. Saw that with a haproxy installation today.

The percent sign means all ip's so localhost is superfluous ... There is no need of the second record with the localhost .

Note
Rectangle 27 0

Using % for host when creating a MySQL user?


If you have a row for an anonymous user from localhost in your users table ''@'localhost' then this will be treated as more specific than your user with wildcard'd host 'user'@'%'. This is why it is necessary to also provide 'user'@'localhost'.

You can see this explained in more detail at the bottom of this page.

Note
Rectangle 27 0

Using % for host when creating a MySQL user?


select Host from mysql.user where User='' and Host='localhost';

(so to start off, if you don't need remote connections to your database, you can get rid of the appuser@'%' user right away)

...there is a reason for setting both types of accounts, this is explained in the mysql docs: http://dev.mysql.com/doc/refman/5.7/en/adding-users.html.

And the fix for this is (as one can guess) to create the appuser@'localhost' (which is more specific that the local host anonymous user and will be used if your appuser connects from the localhost).

If you have an have an anonymous user on your localhost, which you can spot with:

The localhost allows only local connections.

The percent symbol means: any host, including remote and local connections.

and if you just create the user appuser@'%' (and you not the appuser@'localhost'), then when the appuser mysql user connects from the local host, the anonymous user account is used (it has precedence over your appuser@'%' user).

Note