Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grant permissions to a set of databases matching a pattern in MysQL 5.0

I'm lead to understand that the following grants all proveleges to all databases that name begin with 'xian_', but mysql complains about a syntax error near ''xian_...

GRANT ALL PRIVILEGES ON 'xian_%.*' TO xian@'192.168.1.%';

What is the correct syntax? Am I right in thinking that the _ needs escaping to \_ too as it is also a wildcard?

like image 302
Xian Stannard Avatar asked Mar 18 '10 10:03

Xian Stannard


People also ask

How do I grant access to all MySQL databases?

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';

How do I grant multiple privileges in MySQL?

In this syntax: First, specify one or more privileges after the GRANT keyword. If you grant multiple privileges, you need to separate privileges by commas. Second, specify the privilege_level that determines the level to which the privileges apply.

How do I grant select privileges in MySQL?

To grant a privilege with GRANT , you must have the GRANT OPTION privilege, and you must have the privileges that you are granting. (Alternatively, if you have the UPDATE privilege for the grant tables in the mysql system schema, you can grant any account any privilege.)

How do I grant grants in MySQL?

The WITH GRANT OPTION clause gives the user the ability to give to other users any privileges the user has at the specified privilege level. To grant the GRANT OPTION privilege to an account without otherwise changing its privileges, do this: GRANT USAGE ON *.


1 Answers

Use ` instead of ' in the database name, and escape the _

GRANT ALL PRIVILEGES ON `xian\_%`.* TO xian@'192.168.1.%';
like image 98
Drungrin Lenole Avatar answered Sep 23 '22 10:09

Drungrin Lenole