I have the following code:

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

migrated from stackoverflow.com Oct 30 '12 at 23:53

This question came from our site for professional and enthusiast programmers.

  • do you have a table with a list of all the users? – nathan hayfield Oct 30 '12 at 22:29
  • If I was to do so, do I simply insert the necessary columns and named them e.g. Insert_priv? and update the values to Yes? or is it Y? – Mr.Z Oct 30 '12 at 22:34

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:

TO 'user1', 'user2', 'user3', 'user4', 'user5', 'user6';

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).


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

  • is there a method without using phpmyAdmin or php script? I only want to use the commands available to me through mysql – Mr.Z Oct 30 '12 at 22:32
  • Unless you already have the names stored in another table. – Alex Richards Oct 30 '12 at 22:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.