How to fix ER_ROLE_NOT_GRANTED (3530): Role is not granted to user in MySQL

MySQLINTERMEDIATEMEDIUMUpdated Dec 22, 2025ยท 104 views

This MySQL error occurs when attempting to use database privileges through a role that hasn't been properly granted to a user. Roles in MySQL provide a way to group privileges and assign them to users collectively. The error typically appears when executing SQL statements that require specific permissions managed through roles.

Quick fix

Fixes ER_ROLE_NOT_GRANTED (3530): Role is not granted to user

-- Check current user
SELECT CURRENT_USER(), USER();

-- List all roles granted to current user
SHOW GRANTS FOR CURRENT_USER();

-- Alternative: query the grants table
SELECT * FROM mysql.role_edges WHERE TO_USER = USER();

-- Check which roles are currently active
SELECT CURRENT_ROLE();

-- List all available roles in the database
SELECT * FROM mysql.roles_mapping;

-- Check role grants with details
SELECT 
    GRANTEE,
    GRANTED_ROLE,
    IS_GRANTABLE,
    IS_DEFAULT
FROM information_schema.APPLICABLE_ROLES
WHERE GRANTEE = CURRENT_USER();
  1. Check current user roles and grants
  2. Grant the missing role to the user
  3. Activate the role in current session
  4. Configure default roles for automatic activation
mysql โ€” error
-- Check current user
SELECT CURRENT_USER(), USER();
-- List all roles granted to current user
SHOW GRANTS FOR CURRENT_USER();
-- Alternative: query the grants table
SELECT * FROM mysql.role_edges WHERE TO_USER = USER();
-- Check which roles are currently active
SELECT CURRENT_ROLE();
-- List all available roles in the database
SELECT * FROM mysql.roles_mapping;
-- Check role grants with details
SELECT
GRANTEE,
GRANTED_ROLE,
IS_GRANTABLE,
IS_DEFAULT
FROM information_schema.APPLICABLE_ROLES
WHERE GRANTEE = CURRENT_USER();
ER_ROLE_NOT_GRANTED (3530): Role is not granted to user

What this error means

The ER_ROLE_NOT_GRANTED error (MySQL error code 3530) occurs when a user attempts to exercise privileges through a role that hasn't been granted to them, or when trying to manipulate role assignments without proper authorization. Key aspects of this error: 1. **Role-Based Privilege Management**: MySQL 8.0+ introduced role-based access control (RBAC) where privileges are granted to roles, and roles are then granted to users. This provides more manageable privilege administration. 2. **Role Activation**: Even when a role is granted to a user, it must be "active" for the user to exercise its privileges. Roles can be granted but not automatically active. 3. **Hierarchical Role System**: MySQL supports role hierarchies where roles can be granted to other roles, creating complex privilege inheritance chains. 4. **Session-Specific Role Activation**: Role activation can be session-specific, meaning a user might have different active roles in different connections. This error is common in environments using MySQL's role feature for privilege management, especially during application deployment, user onboarding, or privilege restructuring.

Typical symptoms

  • SQL statements fail with "ER_ROLE_NOT_GRANTED (3530): Role is not granted to user"
  • Application users cannot perform database operations they should have access to
  • Privilege errors occur after role assignments or user creation
  • Database migrations or deployment scripts fail due to insufficient privileges
  • Different users experience different access levels despite similar role assignments
  • Errors occur when switching between database connections or sessions
  • Privilege checks succeed in some sessions but fail in others

Common causes

  1. Role was granted but not activated for the current session
  2. Attempting to use SET ROLE with a role not granted to the user
  3. Role grant was revoked but session still tries to use it
  4. User trying to grant a role they don't have GRANT OPTION for
  5. Role hierarchy issues where parent role privileges aren't properly inherited
  6. Default roles not properly configured for automatic activation
  7. Session reset or reconnection without role reactivation
  8. Application connection pooling with stale role assignments
  9. MySQL server restart causing role grant cache invalidation
  10. Incorrect role name or case sensitivity mismatch

How to fix "ER_ROLE_NOT_GRANTED (3530): Role is not granted to user"

1Check current user roles and grants

First, verify what roles are granted to the current user and which are active:

sql
-- Check current user
SELECT CURRENT_USER(), USER();

-- List all roles granted to current user
SHOW GRANTS FOR CURRENT_USER();

-- Alternative: query the grants table
SELECT * FROM mysql.role_edges WHERE TO_USER = USER();

-- Check which roles are currently active
SELECT CURRENT_ROLE();

-- List all available roles in the database
SELECT * FROM mysql.roles_mapping;

-- Check role grants with details
SELECT 
    GRANTEE,
    GRANTED_ROLE,
    IS_GRANTABLE,
    IS_DEFAULT
FROM information_schema.APPLICABLE_ROLES
WHERE GRANTEE = CURRENT_USER();

This will show you what roles are granted to the user and whether they're marked as default roles.

2Grant the missing role to the user

If the role isn't granted to the user, grant it with appropriate privileges:

sql
-- Grant role to user (requires appropriate privileges)
GRANT 'app_user_role' TO 'username'@'host';

-- Grant with admin option (allows user to grant to others)
GRANT 'app_user_role' TO 'username'@'host' WITH ADMIN OPTION;

-- Make role default (automatically active on login)
GRANT 'app_user_role' TO 'username'@'host';
SET DEFAULT ROLE 'app_user_role' FOR 'username'@'host';

-- Or set all granted roles as default
SET DEFAULT ROLE ALL FOR 'username'@'host';

-- Verify the grant worked
SHOW GRANTS FOR 'username'@'host';

-- Check from different perspective
SELECT * FROM mysql.role_edges 
WHERE FROM_USER = 'username' AND FROM_HOST = 'host';

Note: You need appropriate privileges (typically SUPER or GRANT OPTION on the role) to grant roles.

3Activate the role in current session

If the role is granted but not active, activate it for the current session:

sql
-- Activate specific role
SET ROLE 'app_user_role';

-- Activate multiple roles
SET ROLE 'role1', 'role2';

-- Activate all granted roles
SET ROLE ALL;

-- Activate all except some roles
SET ROLE ALL EXCEPT 'admin_role';

-- Check current active roles
SELECT CURRENT_ROLE();

-- Verify privileges are now available
SHOW GRANTS FOR CURRENT_USER();

-- Test with a privilege check
SELECT 
    PRIVILEGE_TYPE,
    IS_GRANTABLE
FROM information_schema.USER_PRIVILEGES
WHERE GRANTEE = CURRENT_USER();

Role activation is session-specific. Each new connection may need role activation unless default roles are configured.

4Configure default roles for automatic activation

To avoid manually activating roles in each session, configure default roles:

sql
-- Set specific role as default for user
SET DEFAULT ROLE 'app_user_role' TO 'username'@'host';

-- Set all granted roles as default
SET DEFAULT ROLE ALL TO 'username'@'host';

-- Set no default roles (manual activation required)
SET DEFAULT ROLE NONE TO 'username'@'host';

-- Check current default role configuration
SELECT 
    DEFAULT_ROLE_USER,
    DEFAULT_ROLE_HOST,
    DEFAULT_ROLE_ROLE
FROM mysql.default_roles
WHERE DEFAULT_ROLE_USER = 'username' AND DEFAULT_ROLE_HOST = 'host';

-- Alternative: check through performance schema
SELECT * FROM performance_schema.default_roles;

-- Apply changes globally (requires appropriate privileges)
FLUSH PRIVILEGES;

Default roles are automatically activated when the user connects, eliminating the need for SET ROLE in each session.

5Check and fix role hierarchy and dependencies

If using role hierarchies, verify the grant chain is complete:

sql
-- Check role-to-role grants
SELECT 
    FROM_USER AS parent_role,
    TO_USER AS child_role
FROM mysql.role_edges 
WHERE FROM_USER LIKE '%role%' AND TO_USER LIKE '%role%';

-- Check if role has required parent role grants
WITH RECURSIVE role_tree AS (
    SELECT TO_USER AS child_role, FROM_USER AS parent_role
    FROM mysql.role_edges
    WHERE TO_USER = 'target_role'
    UNION ALL
    SELECT r.TO_USER, r.FROM_USER
    FROM mysql.role_edges r
    INNER JOIN role_tree rt ON r.TO_USER = rt.parent_role
)
SELECT * FROM role_tree;

-- Grant role to another role (creating hierarchy)
GRANT 'parent_role' TO 'child_role';

-- Check effective privileges through role hierarchy
SHOW GRANTS FOR 'username'@'host' USING 'app_user_role';

-- Revoke and regrant if hierarchy is broken
REVOKE 'app_user_role' FROM 'username'@'host';
GRANT 'app_user_role' TO 'username'@'host';
SET DEFAULT ROLE 'app_user_role' FOR 'username'@'host';

Role hierarchies can be complex. Ensure all necessary parent roles are granted and active.

6Diagnose application connection and pooling issues

For applications with connection pooling, ensure roles are handled correctly:

sql
-- Check connection attributes (for debugging)
SELECT * FROM performance_schema.session_connect_attrs
WHERE PROCESSLIST_ID = CONNECTION_ID();

-- Check current session role state
SELECT 
    CURRENT_USER(),
    CURRENT_ROLE(),
    @@activate_all_roles_on_login
FROM DUAL;

-- MySQL configuration for automatic role activation
SET GLOBAL activate_all_roles_on_login = ON;

-- Or in my.cnf:
[mysqld]
activate_all_roles_on_login = ON

Application code examples:

python
# Python - Ensure role activation on connection
import mysql.connector

config = {
    'user': 'username',
    'password': 'password',
    'database': 'mydb',
    'host': 'localhost',
    'port': 3306,
    'autocommit': True,
    'connection_timeout': 10
}

connection = mysql.connector.connect(**config)
cursor = connection.cursor()

# Activate role after connection
cursor.execute("SET ROLE 'app_user_role'")
connection.commit()
php
// PHP - Role activation
$pdo = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password');
$pdo->exec("SET ROLE 'app_user_role'");

Configure connection pools to execute SET ROLE after establishing connections.

Advanced notes

The ER_ROLE_NOT_GRANTED error involves several advanced MySQL role management concepts:

1. Role Activation Modes: MySQL supports different role activation modes:
- SET ROLE: Manual activation per session
- SET DEFAULT ROLE: Automatic activation on login
- activate_all_roles_on_login: Global setting for automatic activation

2. Role Hierarchies and Inheritance: Roles can be granted to other roles, creating privilege inheritance chains. When a role is activated, all privileges from parent roles become available.

3. Mandatory Roles: MySQL 8.0.19+ supports mandatory roles that are always active for all users, useful for baseline security policies.

4. Role Privilege Updates: When privileges are added to a role, all users with that role (active or default) immediately gain the new privileges.

5. Performance Schema Monitoring: Use Performance Schema tables (performance_schema.active_roles, performance_schema.role_edges) to monitor role usage and grants.

6. Security Considerations:
- Role grants are stored in mysql.role_edges
- Default roles in mysql.default_roles
- Mandatory roles in mysql.mandatory_roles (global variable)
- Regular privilege audits should include role assignments

7. Migration from Legacy Systems: When migrating from MySQL 5.7 or earlier without role support, plan role design carefully to match existing user/privilege structures.

8. Cloud Database Considerations: Managed MySQL services (AWS RDS, Google Cloud SQL, Azure Database for MySQL) fully support roles but may have specific limitations or best practices.

Frequently asked questions

What does "ER_ROLE_NOT_GRANTED (3530): Role is not granted to user" mean?
The ER_ROLE_NOT_GRANTED error (MySQL error code 3530) occurs when a user attempts to exercise privileges through a role that hasn't been granted to them, or when trying to manipulate role assignments without proper authorization. Key aspects of this error: 1. 0+ introduced role-based access control (RBAC) where privileges are granted to roles, and roles are then granted to users.
How do I fix "ER_ROLE_NOT_GRANTED (3530): Role is not granted to user"?
This MySQL error occurs when attempting to use database privileges through a role that hasn't been properly granted to a user. Roles in MySQL provide a way to group privileges and assign them to users collectively. The error typically appears when executing SQL statements that require specific permissions managed through roles.
What causes "ER_ROLE_NOT_GRANTED (3530): Role is not granted to user"?
Role was granted but not activated for the current session Attempting to use SET ROLE with a role not granted to the user Role grant was revoked but session still tries to use it
Is the "ER_ROLE_NOT_GRANTED (3530): Role is not granted to user" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading