How to Fix MySQL Error 3628 (ER_MANDATORY_ROLE)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3628 when you try to drop or revoke a mandatory role. To fix it, remove the role name from the server mandatory role list first. MySQL uses roles to group privileges together for your team and your apps. Some roles are set as mandatory at the server level. This setting grants those roles to every user account on the server. Because every user needs them, MySQL protects these roles from accidental removal. When an admin tries to delete or revoke one, the engine blocks the cha

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You get mysql error 3628 when you try to drop or revoke a mandatory role. To fix it, remove the role name from the server mandatory role list first.

MySQL uses roles to group privileges together for your team and your apps. Some roles are set as mandatory at the server level. This setting grants those roles to every user account on the server. Because every user needs them, MySQL protects these roles from accidental removal. When an admin tries to delete or revoke one, the engine blocks the change. The database then returns SQLSTATE HY000 and stops your query right away.

What causes mysql error 3628 in your database

This error maps to the internal symbol ER_MANDATORY_ROLE inside the MySQL server engine. It fires when a command tries to drop or revoke a protected role. MySQL tracks these required roles in a global system list.

When a role sits in this list, the database locks it in place. You cannot take it away from any single user account. You also cannot delete the role from the database server.

This rule keeps baseline permissions safe across all your database accounts. Still, it also blocks cleanup scripts that try to remove old roles. Automated tools often hit this wall when they rotate team permissions. If a script tries to drop a listed role, the query fails right away. The server tells you that the restriction stays until you exclude the role.

How to diagnose and fix the mandatory role restriction

Before you change any server settings, check why the role is mandatory. Read your current global role list to see every protected role name. Talk to your security team to see if users still need those permissions.

Never grant full admin rights to bypass a role error in production. Instead, update the server role list through a planned change window. First, take the target role name out of the global mandatory role setting. Make sure you keep all other required roles in that list.

Role-Based Access Control (RBAC) + Mandatory Access Control (MAC): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Once you update the runtime setting, the database lifts the lock right away. You can now revoke the role from specific users or drop it. Do not forget to update your main server settings file too. If you skip the file update, the error returns after a server restart.

Test your app connections right after you remove the role. Check your error logs to make sure no active queries fail due to missing grants. If an app still needs those rights, grant them through a standard role.

How to prevent role lockouts during database changes

Role errors often happen when too many people share wide database privileges. You can avoid this problem by keeping your global mandatory role list empty. Grant roles to specific groups instead of every user on the server.

When a role applies only to specific users, you can drop it anytime. You also reduce the risk of giving new accounts too much power. Combine specific roles with data masking to protect sensitive data fields. For example, masking rewrites emails, phone numbers, card numbers, and national IDs in results.

Keep a clear log of every role change across your database servers. Review your active roles each month so old permissions do not pile up. This habit keeps your database clean and stops role errors before they start.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

What does ER_MANDATORY_ROLE mean in MySQL?

ER_MANDATORY_ROLE is the system name for error 3628 with SQLSTATE HY000. It means you tried to drop or revoke a role from the mandatory list.

Can I revoke a mandatory role from just one user?

No, MySQL does not let you revoke a mandatory role from any user. You must remove the role from the global mandatory list first.

Will my changes stay after a MySQL server restart?

Runtime changes only last until the database server restarts or reloads. Save the updated role list in your permanent server settings file to keep it.

The query runs. The emails stay hidden.