Creating MySQL Users Without Over-Granting Access
A practical guide to creating MySQL users, granting narrow privileges, reviewing access, and safely removing accounts.
Authors: Orcaq Team
Database access should be boring in the best possible way: explicit, reviewable, and easy to revoke. MySQL gives teams the primitives they need, but the safest setup depends on using those primitives with restraint.
This mock guide walks through a production-minded user and permission workflow inspired by common MySQL administration patterns.
Start with a Dedicated User
Avoid using the root account for application traffic. Root-level access is useful for administration, but it is too broad for services, dashboards, notebooks, and background jobs.
Create a user for the exact connection boundary you expect:
CREATE USER 'analytics_app'@'localhost' IDENTIFIED BY 'use-a-strong-password';
The host portion matters. localhost limits the account to local connections. % allows connections from any host and should be used only when the network layer and firewall rules are already strict.
Grant Only What the User Needs
For read-only reporting, grant read access to the target schema instead of global privileges:
GRANT SELECT ON product_analytics.* TO 'analytics_app'@'localhost';
For an application account that writes to one database:
GRANT SELECT, INSERT, UPDATE, DELETE
ON app_production.*
TO 'app_service'@'10.0.0.%';
Resist the convenience of ALL PRIVILEGES ON *.*. It is fast to type, but it also turns an application bug or leaked credential into a full database incident.
Review Grants Before Shipping
Make permission review part of release readiness:
SHOW GRANTS FOR 'app_service'@'10.0.0.%';
In Orcaq, this can become a simple checklist:
- Confirm the account is scoped to the right host.
- Confirm privileges match the application behavior.
- Confirm broad privileges such as
DROP,ALTER, orGRANT OPTIONare intentional. - Confirm production accounts are not reused in development.
Revoke Before Removing
When an account is no longer needed, revoke access first, then drop it:
REVOKE ALL PRIVILEGES ON *.* FROM 'analytics_app'@'localhost';
DROP USER 'analytics_app'@'localhost';
This keeps the operational intent clear in audit trails and reduces the chance of leaving stale permissions behind during manual cleanup.
Common Debugging Checks
If a user cannot connect or query data, check these first:
- The username, password, and host match the account definition.
- The service is connecting from the host MySQL expects.
- The account has privileges on the specific database or table being accessed.
- The application is not accidentally using a different connection string.
Permission systems are not just about granting access. They are about making access easy to understand later.
Sources
- DigitalOcean: How to Create a MySQL User and Grant Privileges
