1

I'm learning how to create a user with a query. I found the following to be working on my localhost, but I'm not sure what the percent sign (%) means. It creates the user test_user with % as the host "Host", as displayed in phpMyAdmin, instead of a localhost Host like for other users I have.

CREATE USER 'test_user'@'%' IDENTIFIED BY 'password';

Also, what would I be doing wrong in assigning privileges to this user?

This doens't work:

GRANT SELECT, UPDATE ON test_db.* TO 'test_user'@'localhost';

This works:

GRANT SELECT, UPDATE ON *.* TO 'test_user'@'localhost';
laketuna
  • 3,832
  • 14
  • 59
  • 104
  • possible duplicate of [Using % for host when creating a MySQL user](http://stackoverflow.com/questions/10823854/using-for-host-when-creating-a-mysql-user) – hjpotter92 May 30 '13 at 00:05

3 Answers3

2

The % character in MySQL is a wildcard character for strings. Having a % as the hostname for your user allows them to connect from any host.

You can find more info about it here: MySQL account name reference

j883376
  • 1,125
  • 9
  • 18
1

% is MySQL wildcard, similar to * in regexes and several other places.

Here, it decides that the test_user can connect from any IP.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
1

As far as I know % sign is a wildcard in SQL. So it means that the host for test_user is able to connect from any host/ip.

Dropout
  • 13,653
  • 10
  • 56
  • 109