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,PROCESSfor 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."
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a database, a table and see data in MySQL?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerWhat is the difference between a database, a table, a row and a column?Beginner