0
0
MySQLquery~20 mins

Role-based access in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Role Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Check user privileges with roles
Given a MySQL database with roles assigned to users, what will be the output of the following query?

SELECT user, host, GROUP_CONCAT(DISTINCT role SEPARATOR ', ') AS roles FROM mysql.role_edges GROUP BY user, host;
MySQL
SELECT user, host, GROUP_CONCAT(DISTINCT role SEPARATOR ', ') AS roles FROM mysql.role_edges GROUP BY user, host;
ALists all roles in the database without grouping by user
BReturns an error because GROUP_CONCAT cannot be used with DISTINCT
CLists each user and host with a comma-separated list of roles assigned to them
DReturns only users without any roles assigned
Attempts:
2 left
💡 Hint
GROUP_CONCAT aggregates values per group; DISTINCT avoids duplicates.
🧠 Conceptual
intermediate
1:30remaining
Understanding role inheritance in MySQL
In MySQL role-based access control, if role A is granted to role B, and role B is granted to user U, which of the following is true?
AUser U inherits privileges from both role A and role B
BUser U only inherits privileges from role B, not role A
CUser U must be granted role A directly to inherit its privileges
DRole inheritance is not supported in MySQL
Attempts:
2 left
💡 Hint
Think about how roles can be nested in MySQL.
📝 Syntax
advanced
2:00remaining
Identify the correct syntax to create a role and grant privileges
Which of the following MySQL statements correctly creates a role named 'report_viewer' and grants SELECT privilege on the 'sales' database to it?
ACREATE ROLE report_viewer; GRANT SELECT ON sales TO report_viewer;
BCREATE ROLE report_viewer; GRANT SELECT ON sales.* TO report_viewer;
CCREATE ROLE 'report_viewer'; GRANT SELECT ON sales.* TO 'report_viewer';
DCREATE ROLE 'report_viewer'; GRANT SELECT ON sales TO 'report_viewer';
Attempts:
2 left
💡 Hint
Role names are identifiers, not strings; privileges must specify database and tables.
optimization
advanced
2:30remaining
Optimizing role privilege checks
You want to quickly check all privileges a user has through roles in MySQL. Which query is the most efficient to get all privileges for user 'alice' including inherited roles?
ASELECT * FROM information_schema.role_table_grants WHERE grantee IN (SELECT role FROM mysql.role_edges WHERE user = 'alice') OR grantee = 'alice';
BSELECT * FROM mysql.user WHERE user = 'alice';
CSELECT * FROM mysql.role_edges WHERE user = 'alice';
DSELECT * FROM information_schema.role_table_grants WHERE grantee = 'alice';
Attempts:
2 left
💡 Hint
Consider roles assigned to the user and privileges granted to those roles.
🔧 Debug
expert
3:00remaining
Debugging role assignment failure
A DBA runs:

GRANT 'data_analyst' TO 'bob'@'localhost';

But receives an error. What is the cause?
AGRANT cannot be used to assign roles
BUser 'bob'@'localhost' does not exist
CRole 'data_analyst' does not exist
DRole name should not be in quotes in GRANT statement
Attempts:
2 left
💡 Hint
Check syntax for role names in GRANT statements.