14

I have the following code:

GRANT SELECT,INSERT,UPDATE ON db1.*
TO ‘user’@example.com;

I am a beginner in mySQL, I was wondering if there is a method in which I can specific the privileges for every user in this domain network without having to type the above code for each user? %wildcard?

Also is there any method such as using a table where I can manage all the privileges of said users

Mr.Z
  • 241
  • 1
  • 2
  • 4

3 Answers3

13

The GRANT syntax allows you to specify multiple users in a single query. You can't do it with a wildcard, but if you already have the list you can do this:

GRANT SELECT,INSERT,UPDATE ON db1.*
TO 'user1', 'user2', 'user3', 'user4', 'user5', 'user6';
Kip
  • 231
  • 2
  • 4
2

As documented under GRANT Syntax:

Account Names and Passwords 

[ deletia ]

You can specify wildcards in the host name. For example, user_name@'%.example.com' applies to user_name for any host in the example.com domain, and user_name@'192.168.1.%' applies to user_name for any host in the 192.168.1 class C subnet.

The simple form user_name is a synonym for user_name@'%'.

MySQL does not support wildcards in user names.

However, you can also manage account permissions by manipulating the MySQL grant tables directly (and then executing FLUSH PRIVILEGES).

eggyal
  • 331
  • 2
  • 8
0

You could write a PHP script to grant each person access. However I would not recommend creating new MySQL accounts for each user. Your application should deal with all of the read / write permissions

ajtrichards
  • 101
  • 1