MySQL uses a privilege system to control what each user can do. Privileges can be granted at four levels: global, database, table, and column. The principle of least privilege dictates that users should only have the permissions they strictly need.
GRANT Syntax
The GRANT statement assigns privileges to a user. You specify the privilege type, the scope (which database/table), and the user. After granting, run FLUSH PRIVILEGES to ensure the changes take effect (though it is usually automatic with GRANT).
Common Privilege Types
- SELECT — read data
- INSERT — add rows
- UPDATE — modify rows
- DELETE — remove rows
- EXECUTE — run stored procedures
- ALL PRIVILEGES — everything (avoid for application users)