Using Wildcards

You can grant privileges to usernames that match wildcard criteria by using the % and _ wildcard characters in the username.

You might actually want to create a user that can access the database from any remote host using the same username and password without needing to create a separate username for each possible host. Using % as the host part of the username accomplishes this, as shown in the following example:

mysql> CREATE USER 'chris@%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT SELECT, INSERT
    -> ON mysql10.products
    -> TO 'chris@%';
Query OK, 0 rows affected (0.00 sec)

Wildcard Usernames

The username in a CREATE USER, GRANT, or REVOKE command must be enclosed in quotes if it contains ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.