Skip to content

Database Authorization & Access Control | Complete Guide to User Permissions & Security

Authorization is the process that determines what an authenticated user is allowed to do within the database. It defines permissions and access levels for different users or roles.

Access Control enforces these permissions by restricting database actions like reading, writing, or deleting data.

  • To protect database objects (tables, views, schemas, etc.).
  • To ensure users perform only authorized operations.
  • To implement least privilege principle, minimizing damage from accidental misuse or attacks.
TypeDescription
Discretionary Access Control (DAC)Access rights are granted or revoked by the data owner using commands like GRANT or REVOKE.
Mandatory Access Control (MAC)Access is controlled by a central authority based on predefined policies (e.g., government-level databases).
Role-Based Access Control (RBAC)Permissions are assigned to roles, and users are assigned roles (common in enterprise DBMS).
  1. GRANT: To assign privileges.

    GRANT SELECT, INSERT ON student TO 'teacher'@'localhost';
  2. REVOKE: To remove privileges.

    REVOKE INSERT ON student FROM 'teacher'@'localhost';
PrivilegeDescription
SELECTRead data from a table/view.
INSERTAdd new records.
UPDATEModify existing records.
DELETERemove records.
CREATE / DROPCreate or delete database objects.
EXECUTERun stored procedures or functions.
  1. User Level: Access to database or schema.
  2. Object Level: Access to specific tables, views, or functions.
  3. Column Level: Restrict visibility to specific columns (useful for sensitive data like salary or password).
  4. Row Level: Access limited to certain rows based on user identity (via WHERE clauses or policies).

Relationship Between Authentication and Authorization

Section titled “Relationship Between Authentication and Authorization”
AspectAuthenticationAuthorization
PurposeVerifies who the user is.Determines what the user can do.
StagePerformed before authorization.Follows successful authentication.
Based onIdentity verification (passwords, tokens).Access policies, roles, and privileges.
OutcomeGrants or denies login.Grants or denies specific actions.

Suppose a banking database has two roles:

  • Admin: Can view and modify all customer data.
  • Teller: Can only view customer balances.

Implementation:

CREATE ROLE teller;
CREATE ROLE admin;
GRANT SELECT ON accounts TO teller;
GRANT ALL PRIVILEGES ON accounts TO admin;
CREATE USER 'rahul'@'localhost' IDENTIFIED BY 'pass123';
GRANT teller TO 'rahul'@'localhost';

Here, authentication verifies Rahul’s identity, and authorization restricts his access only to viewing data.


ConceptDefinitionKey MechanismExample
AuthenticationVerifies user identityPasswords, MFA, TokensCREATE USER
AuthorizationDetermines access levelRoles, GRANT, REVOKEGRANT SELECT
Access ControlEnforces authorization rulesDAC, MAC, RBACRole-based privileges