I understand how to create a new user with privileges, but what is the correct way to change privileges for users that are already created?

We are running a DB audit and some of the users have way more access then is needed. Plus I don't know the passwords for most of these MySQL users, so I don't want to delete them and create new ones.

up vote 83 down vote accepted

To list users:

select user,host from mysql.user;

To show privileges:

show grants for 'user'@'host';

To change privileges, first revoke. Such as:

revoke all privileges on *.* from 'user'@'host';

Then grant the appropriate privileges as desired:

grant SELECT,INSERT,UPDATE,DELETE ON `db`.* TO 'user'@'host';

Finally, flush:

flush privileges;

The MySQL documentation is excellent:

http://dev.mysql.com/doc/refman/5.0/en/user-account-management.html

  • 1
    I misunderstood the use of revoke. Thanks. – Clutch Feb 23 '10 at 20:10
  • 3
    Well without revoke, it will be dublicates privileges; – Sergey Sep 27 '12 at 12:38
  • 6
    mysql documentation is near unreadable, this answer is much better – Timo Huovinen Mar 1 '16 at 10:02
  • I think (revoke all privileges on . from 'user'@'host'; ) should be (revoke all on . from 'user'@'host';) Thanks, – Nicholas Jul 12 at 14:42

this answer is plain wrong

"flush privileges" does not apply to privileges set with grant.

the above process results in the user having no privilege at all between the moment the revoke and the grant queries are run, and additionally flushing the grants cache for no reason

__

this would work if you perform regular queries against the mysql.user table rather than using grants and if the server does not crash or stop between the queries.

  • This seems to be a comment to an answer, not an answer. – RalfFriedl Aug 16 at 16:52

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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