0

I was always told that "%" means every host except localhost.

However I have created a user4@"%" and I can connect to from localhost.

screenshot

So now I am a bit confused regarding this. Can anyone clarify this for me, please?

ptor
  • 3
  • 1

1 Answers1

2

I was always told that "%" means every host except localhost.

This is plain wrong.

% is a wildcard. It matches 0 or more of any character:

SQL pattern matching enables you to use _ to match any single character and % to match an arbitrary number of characters (including zero characters)

Thus % in the hostname field matches any host, including localhost.

vidarlo
  • 3,775
  • 1
  • 12
  • 25
  • Thanks for the information. – ptor Nov 24 '21 at 00:32
  • But, I think that user@host is treated specially. – Rick James Nov 24 '21 at 01:28
  • 1
    In the documentation says that @"localhost" is treated differently on UNIX systems because they use a UNIX socket as protocol for local connections. However it doesn't say what's the difference. According to my teacher, user1@"%" should not be allowed to connect to the server locally but my tests prove otherwise. – ptor Nov 24 '21 at 02:16
  • The client defaults to attempting socket communication for localhost. That doesn't change mysql's wildcard handling however. Your tests are however entirely right, and matches the documentation re. wildcards - and your teacher is wrong. – vidarlo Nov 24 '21 at 07:57