O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required