How to Fix MySQL Error 3901 (ER_PARTIAL_REVOKE_AND_DB_GRANT_BOTH_EXISTS)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3901 when a database privilege exists as a partial revoke and a schema grant at once. You fix it by removing the conflicting row from the database grant table and refreshing server privileges. This failure uses the symbol ER_PARTIAL_REVOKE_AND_DB_GRANT_BOTH_EXISTS and returns SQLSTATE HY000. It tells you that the grant tables hold two opposing rules for the same user and schema. When this conflict happens, the database blocks privilege changes until you clean up the grant st

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 3901 when a database privilege exists as a partial revoke and a schema grant at once. You fix it by removing the conflicting row from the database grant table and refreshing server privileges.

This failure uses the symbol ER_PARTIAL_REVOKE_AND_DB_GRANT_BOTH_EXISTS and returns SQLSTATE HY000. It tells you that the grant tables hold two opposing rules for the same user and schema. When this conflict happens, the database blocks privilege changes until you clean up the grant state.

What causes mysql error 3901 in the database engine

MySQL lets admins grant global rights to a user and then block those rights on one schema. The engine calls this feature a partial revoke. It stores these schema blocks inside the global user table as a JSON restriction list.

At the same time, the server tracks schema grants inside the database privilege table. A user cannot have a schema restriction and a schema grant for the exact same right. If both records show up at the same time, the server triggers mysql error 3901.

This clash never happens during normal grant and revoke actions. Instead, it happens when someone edits the system grant tables by hand. An admin might run a direct write statement on the system schema instead of using standard privilege commands.

Upgrades and backups can also trigger this bug. If a team restores an old backup over a newer server, the grant tables can get out of sync. Replication from an older source to a newer replica can also mix direct table edits with partial revokes.

How to find and fix the privilege conflict in production

First, read the error message to find the exact privilege name and database name. Next, check the current grants for the affected user account. Look at both the global user record and the database grant table for matching entries.

Do not fix this problem by giving the user full admin rights across the whole server. Also, do not turn off grant table checks on your production host. Those shortcuts expose your data to every app and user on the network.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Instead, decide whether the user should have that right on the target schema. If the user needs the right, remove the partial revoke by granting the right at the schema level. If the standard command fails due to the conflict, clear the stale schema row first.

Once the duplicate record is gone, tell the server to reload the grant tables into memory. Then use standard grant or revoke statements to set the final role for that user. Always test the user account from a client session to confirm the rules work as planned.

How to prevent grant table conflicts in the future

The best way to stop this error is to ban direct writes to system tables. Train your team to use built-in account management statements for every role change. Standard commands check for conflicts before they write data to disk.

You should also review how your team manages database users across staging and production. Store role definitions in version control and run them through a central pipeline. Keep user permissions small and clear so you do not need complex global rules with schema exceptions.

When you limit who can run admin commands, you lower the risk of broken system tables. You can also mask sensitive fields like emails, phone numbers, card numbers, and national IDs in query results. Masking rewrites matched fields in results, so fewer people need broad database rights in the first place.

Add wire guardrails and masking beside MySQL

Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.

With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.

Frequently asked questions

What does ER_PARTIAL_REVOKE_AND_DB_GRANT_BOTH_EXISTS mean?

It means a single database privilege is listed as both allowed and blocked for the same schema. The server sees a partial revoke in the user table and a grant in the database table.

Can I fix mysql error 3901 by turning off partial revokes?

You cannot turn off the partial revoke setting while any partial revokes still exist on the server. You must resolve the conflicting records and remove all partial revokes before you change that system setting.

Why did my database grant tables get out of sync?

Grant tables get out of sync when someone edits system tables with direct write queries. Failed upgrades, mismatched backups, or cross-version replication can also leave conflicting rows in the system schema.

The query runs. The emails stay hidden.