Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I grant access to databases with prefix then wild card?

Tags:

mysql

Can I GRANT ALL PRIVILEGES ON a*.* TO 'my_user'@'%' WITH GRANT OPTION; ?

I just want the user to only have access to all databases beginning with "my_prefix_" but not, for instance, to "mysql".

like image 248
Mawg says reinstate Monica Avatar asked May 13 '11 07:05

Mawg says reinstate Monica


People also ask

How do I grant access to my database?

Database-Specific Privileges To GRANT ALL privileges to a user , allowing that user full control over a specific database , use the following syntax: mysql> GRANT ALL PRIVILEGES ON database_name. * TO 'username'@'localhost';


1 Answers

Yes, you can.

This is what phpMyAdmin does when I make a user jaap and use the option Grant all privileges on wildcard name (username\_%):

GRANT ALL PRIVILEGES ON  `jaap\_%` . * TO  'jaap'@'localhost'; 

That's what you mean, right?

PS
As you can see, the _ is escaped, because in (My)SQL an unescaped _ means 'one character'. (Like . in regex.) In this case, you want the _ to be literal, so databases must start with jaap_

like image 106
Rudie Avatar answered Sep 30 '22 20:09

Rudie