Skip to main content

Fixed: "ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES" in MySQL

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

GRANT PROCESS ON inventory.* TO ... failed with ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES. The syntax is fine. Some privileges apply to the whole server, and can't be limited to one database.

What I Was Doing​

I was setting up an account for looking at locks, on MySQL 9.7.4 in Docker, and wanted to keep its rights as small as possible by naming one database:

mysql: root session
CREATE USER IF NOT EXISTS 'lock_viewer'@'%' IDENTIFIED BY 'choose-a-strong-password';
GRANT PROCESS ON inventory.* TO 'lock_viewer'@'%';

What I Expected​

Query OK.

What I Got​

Output (the GRANT)
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

GRANT PROCESS ON inventory.* failing with ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES.

What I Checked​

The table of privileges. MySQL's privileges page gives each one a context, and PROCESS has "Server administration". It also describes it as controlling "access to information about threads executing within the server".

Why It Happens​

PROCESS shows what every session on the server is doing, whatever database they're using. Limiting it to one database wouldn't mean anything, so MySQL refuses. The message's "global privileges" are rights that only exist for the whole server.

The Fix​

Grant it on *.*, and keep the rest of the account narrow:

mysql: root session
GRANT PROCESS ON *.* TO 'lock_viewer'@'%';

*.* here doesn't mean access to every table. PROCESS is the only right it gives, and this account still can't read your data. How to Let a MySQL User See Locks and Transactions has the full set of grants.

After the Fix​

Output
Query OK, 0 rows affected (0.001 sec)

GRANT PROCESS ON . succeeding with Query OK.

Common Mistakes​

MistakeWhat happensDo this instead
Reading ON *.* as "all data"Only the named privilege appliesCheck with SHOW GRANTS
Using GRANT ALL ON *.* to get past itThe account can do anythingGrant only the one you need
Trying other server-wide rights on a databaseThe same errorUse *.* for them

Troubleshooting​

SymptomLikely causeFix
The same error for another privilegeIt's server-wide tooCheck its context on the privileges page
Access denied; you are not allowed to grantThe granting account lacks itUse an administrator

Conclusion​

ERROR 1221 means the privilege belongs to the whole server. Grant it on *.*, which gives that one right and no others.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.