HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How to grant multiple users privileges; MySQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
privilegesgrantmysqlmultiplehowusers

Problem

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

Solution

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

Code Snippets

GRANT SELECT,INSERT,UPDATE ON db1.*
TO 'user1', 'user2', 'user3', 'user4', 'user5', 'user6';

Context

StackExchange Database Administrators Q#27920, answer score: 13

Revisions (0)

No revisions yet.