MySQL Privileges

How to grant specific privileges to users

This is a list of usual possible privileges that users can enjoy.

  • ALL PRIVILEGES – as we saw previously, this would allow a MySQL user full access to a designated database (or if no database is selected, global access across the system)
  • CREATE – allows the user to create new tables or databases
  • DROP – allows the user to delete tables or databases
  • DELETE – allows the user to delete rows from tables
  • INSERT – allows the user to insert rows into tables
  • SELECT – allows the user to use the SELECT command to read through databases
  • UPDATE – allow the user to update table rows
  • GRANT OPTION – allows the user to grant or remove other users’ privileges

To grant specific privilege to a specific user, use this command:

GRANT type_of_privilege ON database_name.table_name TO ‘username’@'localhost’;

To revoke specific privilege from a specific user, use this command.

REVOKE type_of_privilege ON database_name.table_name FROM ‘username’@‘localhost’;