CertGrid CertGrid
Troubleshooting·MySQL

MySQL Roles and Default Roles

A role is granted, the account still cannot read the schema, and `SET ROLE` in the same command does not help - because the database is selected before the role is activated. `SET DEFAULT ROLE` is the fix, and nothing in the error says so.

Users and Privileges Guide 19 of 45 Intermediate

Written against the versions above. Roles are MySQL 8.0+. On 5.7 the equivalent is granting the same privileges to every account individually, which is what roles exist to stop.

Every command on this page ran on db-a01.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB

Before you start

  1. Create a role and put privileges on it

  2. Grant the role to an account and read the grants

  3. Try to use it, and fail twice

  4. Make the role activate on connection

Official sources