π€ Users & Permissions are fundamental security features in relational database systems. They determine who can access the database and what actions they are allowed to perform. Properly managing users and permissions protects sensitive data, prevents unauthorized changes, and helps organizations implement secure access control.
π What are Users and Permissions?
A database user is an account that connects to a database. Permissions (also called privileges) define the operations that user is allowed to perform, such as reading data, inserting records, updating rows, creating tables, or managing other users.
Information
π― Why are Users & Permissions Important?
Access control is one of the most important aspects of database security.
- π Protect confidential data.
- π Prevent unauthorized modifications.
- π Control who can access database objects.
- π Support auditing and accountability.
- π Enforce business security policies.
- π Reduce the impact of accidental or malicious actions.
π₯ Common Types of Database Users
| User Type | Typical Responsibility |
|---|---|
| Database Administrator (DBA) | Full database administration and security. |
| Application User | Used by applications to access required data. |
| Developer | Create and modify database objects during development. |
| Reporting User | Read-only access for reports and analytics. |
| Guest/User Account | Limited or restricted access. |
π Common Database Privileges
| Privilege | Description |
|---|---|
| SELECT | Read data from tables or views. |
| INSERT | Add new records. |
| UPDATE | Modify existing records. |
| DELETE | Remove records. |
| CREATE | Create database objects. |
| ALTER | Modify database objects. |
| DROP | Delete database objects. |
| EXECUTE | Run stored procedures or functions. |
π Creating a User
Creating database users allows administrators to provide individual accounts with controlled access.
Create User (Generic Example)
CREATE USER username
IDENTIFIED BY password;Remember
π Granting Permissions
Use the GRANT statement to assign privileges to users.
Grant SELECT Permission
GRANT SELECT
ON Customers
TO username;The user can now read data from the Customers table but cannot modify it unless additional privileges are granted.
π Grant Multiple Permissions
Grant Multiple Privileges
GRANT
SELECT,
INSERT,
UPDATE
ON Customers
TO username;π Revoking Permissions
Permissions can be removed using the REVOKE statement.
Revoke Permission
REVOKE UPDATE
ON Customers
FROM username;π Roles
Instead of assigning permissions to every user individually, many database systems support roles. A role groups related privileges, and users are assigned one or more roles.
Role Concept
CREATE ROLE ReportingRole;
GRANT SELECT
ON Customers
TO ReportingRole;Tip
π‘οΈ Principle of Least Privilege
Every user should receive only the permissions required to perform their job.
| Good Practice | Poor Practice |
|---|---|
| Grant only required permissions. | Grant full administrative access to everyone. |
| Use read-only accounts for reports. | Allow reporting users to modify data. |
| Use separate accounts for applications. | Share one administrator account. |
| Review permissions regularly. | Never audit user access. |
Important
π Object-Level vs Database-Level Permissions
| Permission Type | Example |
|---|---|
| Object-Level | Allow SELECT on a specific table. |
| Schema-Level | Allow creating objects within a schema. |
| Database-Level | Allow creating new tables in a database. |
| Server-Level | Administrative control over the database server. |
πΌ Real-World Applications
- π¦ Restrict access to financial records.
- π₯ Protect confidential patient information.
- π Separate customer, administrator, and reporting access.
- π’ Secure enterprise applications.
- π Create read-only reporting accounts.
- βοΈ Manage cloud-hosted database security.
ποΈ Database Compatibility
All major relational database systems support users, permissions, and roles, although the available privileges and SQL syntax differ between products.
| Database System | User & Permission Support |
|---|---|
| MySQL | β Users, roles, and privilege management. |
| PostgreSQL | β Roles and privilege-based security. |
| SQL Server | β Logins, users, roles, and permissions. |
| Oracle | β Users, roles, profiles, and privileges. |
| SQLite | β οΈ No built-in user management; access is typically controlled by the application or operating system. |
β οΈ Common Mistakes
- β Granting excessive permissions.
- β Using administrator accounts for everyday application access.
- β Sharing database user accounts.
- β Forgetting to revoke permissions when users change roles.
- β Ignoring periodic permission audits.
- β Storing database credentials insecurely.
Warning
β οΈ Best Practices
Best Practice
π Key Points to Remember
- π Users identify who can access a database.
- π Permissions define what actions users can perform.
- π GRANT assigns privileges.
- π REVOKE removes privileges.
- π Roles simplify permission management.
- π Always follow the principle of least privilege.