Skip to content

20. Users and Permissions

Updated
17 Sept 2026
1 min read
8 sections
Page 22 of 22
Data Engineering

Users and Permissions

Database users control who can connect and what they can do. Good permission design protects data from accidental or unauthorized changes.

Create a user

sql
CREATE USER "report_user"@"localhost"
IDENTIFIED BY "strong_password_here";

The part before @ is the username. The part after @ is the host the user can connect from.

Grant read-only access

sql
GRANT SELECT
ON companydb.*
TO "report_user"@"localhost";

This user can read every table in companydb, but cannot insert, update, delete, or alter tables.

Grant access to one table

sql
GRANT SELECT, INSERT
ON companydb.customers
TO "app_writer"@"localhost";

Use table-level grants when a user only needs part of a database.

Apply privilege changes

Modern MySQL applies many grant changes immediately, but FLUSH PRIVILEGES is still common after direct privilege table changes.

sql
FLUSH PRIVILEGES;

Revoke permissions

sql
REVOKE INSERT
ON companydb.customers
FROM "app_writer"@"localhost";

Remove a user:

sql
DROP USER "report_user"@"localhost";

Check grants

sql
SHOW GRANTS FOR "report_user"@"localhost";

Least privilege

Least privilege means each user gets only the permissions needed for their job.

User typeTypical permissions
Dashboard userSELECT only
Application writerSELECT, INSERT, UPDATE, maybe DELETE
Migration userSchema change permissions such as CREATE, ALTER, DROP
AdminFull privileges, used rarely

Avoid using the root user in applications. Create specific users for applications, dashboards, and maintenance tasks.