MySQL Grant Privileges

Profile picture for user arilio666

If we want to grant some privileges over to a user's table, MySQL can do that. GRANT can give permissions to any combinations of SELECT, INSERT, UPDATE, DELETE, INDEX, CREATE, ALTER, DROP, GRANT OPTION, and ALL.

Syntax

GRANT privileges ON object FROM user;

Privileges

  • Here are some of the privileges SELECT, INSERT, UPDATE, DELETE, INDEX, CREATE, ALTER, DROP, GRANT OPTION, and ALL.
  • In these privileges, Grant has the power to take the ability to perform these queries off a user.

Example

  • If a user named mary has all the privileges available granted to him.
  • One day, two specific privileges should be Granted on his table called accounts such as INSERT and SELECT.
Grant SELECT, INSERT ON accounts FROM 'mary'@'localhost';

Simple as that.

  • Say now, for example. We want to Grant all the privileges of mary's accounts table. We can use this.
Grant ALL ON accounts FROM 'mary'@'localhost';
  • Suppose there is a contact list of users, and you want to Grant UPDATE privileges to them. We can use this.
Grant UPDATE ON contacts FROM '*'@'localhost';

Conclusion:

So simple as that, this is how Grant works.

Tags