What are GRANT and REVOKE, and what privileges should an application user get?

IntermediateConceptMySQL
Answer

Short answer

GRANT gives a user permissions on databases, tables or columns; REVOKE removes them. An application user should get only what it needs — usually SELECT, INSERT, UPDATE, DELETE on its own database — while schema changes are done by a separate migration user.

Examples

-- App user: data only, one database
GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'shop_app'@'10.0.%';

-- Migration user: can change structure
GRANT CREATE, ALTER, DROP, INDEX, REFERENCES, SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'shop_migrator'@'10.0.%';

-- Read-only reporting user
GRANT SELECT ON shop.* TO 'reporting'@'10.0.20.%';

-- Remove a permission
REVOKE DELETE ON shop.* FROM 'shop_app'@'10.0.%';

Privilege levels

*.* (global) → shop.* (database) → shop.orders (table) → specific columns.

Avoid

  • GRANT ALL PRIVILEGES ON *.* for apps.
  • WITH GRANT OPTION (lets the user give away permissions).
  • Global privileges like FILE, SUPER, PROCESS for app users.

What to say in the interview

"GRANT and REVOKE manage privileges at global, database, table or column level. Following least privilege, the app gets DML on its own schema only, a separate migration user gets DDL, and reporting users get SELECT."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MySQL basics

More on MySQL