user1032531 user1032531 - 8 days ago 5
MySQL Question

What does "\_%" mean regarding MySQL database permissions?

I created a new MySQL user

homestead
using phpMyAdmin and when doing so, created a new database with the same name. As seen below,
homestead
was given permissions to two databases:
homestead
and
homestead\_%
.

What does the
\_%
signify? I later created a new database
laravel
, and wish user
homestead
to have the same permissions as the first table. Do I need to also add permissions to
laravel\_%
?

enter image description here

Answer

% and _ are simply SQL wildcards. The GRANT syntax allows them:

The _ and % wildcards are permitted when specifying database names in GRANT statements that grant privileges at the database level.

You may notice that _ is escaped (\_):

if you want to use a _ character as part of a database name, you should specify it as \_ in the GRANT statement, to prevent the user from being able to access additional databases matching the wildcard pattern; for example, GRANT ... ON `foo\_bar`.* TO ....

It's apparently a way to extend the privileges to any database that starts with homestead_...

Comments