SlideShare a Scribd company logo
A quick tour of
MySQL 8.0 roles
Giuseppe Maxia
Software explorer
!1
@datacharmer
#dataopsbarcelona
Who's this guy?
About me
‣ Giuseppe Maxia, a.k.a. "The Data Charmer"
‣ Software Explorer at VMware
‣ Several decades development and DB
experience
‣ Long timer MySQL community member.
‣ Blog: http://datacharmer.blogspot.com
‣ Twitter: @datacharmer
!2
Disclaimer
•None of what I say has
anything to do with my
company.

•I also don’t work for Oracle.
A long coveted feature finally arrives
Roles overview
‣ Available since MySQL 8.0.0
‣ Created like an user
‣ Granted like privileges
‣ Need to be activated (with tricks)
!4
Up until the current GA (MySQL 5.7) there were no roles
Before roles
‣ CREATE USER
‣ GRANT, GRANT, and more granular GRANT
‣ CREATE USER
‣ GRANT, GRANT again, and then GRANT
‣ CREATE USER
‣ GRANT, GRANT, GRANT, GRANT, oops!
!5
In short: a lot of work,
with many chances to make mistakes
Why bother with this new feature?
Advantages of roles
‣ Faster user administration
• define a role once
• assign it many times
‣ Centralised grants handling
• grant and revoke privileges to roles
• No need to edit all users profiles
‣ Easy to understand grants statistics
!6
A BAD example. (1)
!7
So far, so good
A BAD example. (2)
!8
WHAT DID JUST HAPPEN ? STAY TUNED TO FIND OUT
!9
Roles
usage
1CREATE ROLE
3CREATE USER
2
GRANT
PRIVILEGES to
ROLE
4GRANT ROLE
TO USER
5SET (DEFAULT)
ROLE
Like creating a user
Create role
CREATE ROLE r_lotr_dev;
## NOTE: there is no "IDENTIFIED" clause
!10
Same as we do it with users
grant privileges to role
GRANT ALL ON lotr.* TO r_lotr_dev;
!11
This one is already known
Create user
CREATE USER aragorn IDENTIFIED BY
'lotrpwd';
!12
We grant a role in a way similar to granting a privilege
Grant role to user
GRANT r_lotr_dev TO aragorn;
## NOTE: there is not an "ON" clause
## in the GRANT statement.
!13
The role needs to be activate
Set [default] role
ALTER USER aragorn DEFAULT ROLE
r_lotr_dba;
## OR
SET DEFAULT ROLE r_lotr_dba
TO aragorn;
!14
There is more than one way to do it
Unfortunately
Some important points
!15
Grants are the total of all roles privileges
A user can be granted more roles
‣ User can have many roles

‣ The default role can be a list of roles
!16
This may cause some confusion
Roles are saved in 'user' table
‣ Roles are users without login (= account locked
and expired password)
!17
It is there, but you can't see it
Granting a role to a user is not enough
‣ When we grant a privilege, the user can use it
immediately.

‣ When we grant a role, we first need to set the
default.
!18
This may look tricky, but it is really simple
We can grant a user to a user
‣ Roles are users without login

‣ But roles with login (i.e. users) can be granted.

‣ Privileges are assigned regardless of the host of
the user.

GRANT root@'localhost' to someuser;
‣ user someuser@'%' has all privileges of root from
any host

!19
You can lose track easily here
SET ROLE anyone?
‣ SET ROLE role_name is a session assignment of
a role

‣ SET DEFAULT ROLE role_name is a permanent
assignment of a role for a user

‣ SET ROLE DEFAULT means assign the default
role to this user for the session.
!20
Sadly, it's up to the DBA's ingenuity
Telling roles from users
‣ Roles are users with expired password and locked
account.

‣ A good workaround is using a naming convention
to tell roles apart (e.g. "r_something")
!21
There is a feature request about this matter,
but I haven’t seen any progress on it.
We have two new tables in 'mysql' DB dedicated to roles
Tables for roles
‣ role_edges reports which roles are assigned to
which users.

‣ default_roles takes track of the current default
roles assigned to users.
!22
Roles in action
!23
!24
Create roles
!25
Create users and apply roles
!26
Users and roles
!27
Finding roles
empirically
!28
role_edge table
(Which roles were assigned)
!29
default_roles table
(Which roles are set as default)
!30
Who are the DBAs?
!31
Who are the developers?
!32
Roles summary
!33
Default roles summary
!34
user with default role
!35
User without default role
!36
User without default role
!37
SET ROLE is not permanent
Back to the BAD example. (2)
!38
Back to the BAD example. (3)
!39
It’s a all-or-nothing option
Roles can be active by default
‣ Starting in 8.0.2

‣ You can use option activate_all_roles_on_login
• When enabled, all roles become active by default
‣ And mandatory_roles

• When set, all users will get the role(s) defined
!40
Example with mandatory roles (1)
mysql> create schema lotr;
Query OK, 1 row affected (0.00 sec)
mysql> grant select on lotr.* to r_lotr_reader;
Query OK, 0 rows affected (0.00 sec)
mysql> set global mandatory_roles='r_lotr_reader';
Query OK, 0 rows affected (0.00 sec)
mysql> create user dummy identified by 'msandbox';
Query OK, 0 rows affected (0.00 sec)
!41
Example with mandatory roles (2)
$ mysql lotr -u dummy -p
ERROR 1044 (42000): Access denied for user 'dummy'@'%'
to database ‘lotr'
# ====== as root ========
mysql> set global activate_all_roles_on_login=1;
$ mysql lotr -u dummy -p
mysql> show grants;
+------------------------------------------+
| Grants for dummy@% |
+------------------------------------------+
| GRANT USAGE ON *.* TO `dummy`@`%` |
| GRANT SELECT ON `lotr`.* TO `dummy`@`%` |
| GRANT `r_lotr_reader`@`%` TO `dummy`@`%` |
+------------------------------------------+
3 rows in set (0.00 sec)
!42
Example with mandatory roles (3)
$ mysql lotr -u root -p
mysql> show grantsG
*** 1. row ***
Grants for root@localhost: GRANT SELECT, INSERT, UPDATE, DELETE,
CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER,
SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE,
REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE
ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE,
CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION
*** 2. row ***
Grants for root@localhost: GRANT
BACKUP_ADMIN,BINLOG_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,GROUP_REPL
ICATION_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_SLAVE_ADMIN,RESOURCE_
GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SET_USER_ID,SYSTEM_VARIABLES_AD
MIN,XA_RECOVER_ADMIN ON *.* TO `root`@`localhost` WITH GRANT OPTION
*** 3. row ***
Grants for root@localhost: GRANT SELECT ON `lotr`.* TO
`root`@`localhost`
!43
Roles are a great feature, but they could be better
Wish list
‣ Missing information_schema (or sys) views
• List of global roles
• List of roles enabled for the current session
• List of default roles
• List of users for a given role
‣ Roles active by default
!44
Latest additions
‣ In 8.0.3+

‣ You can set the default role within CREATE
USER.
!45
Q & A
!46
@datacharmer
#dataopsbarcelona

More Related Content

DOC
Sap ehp6 to ehp7 upgradation projects
PDF
UDA-Componentes RUP. Mantenimiento (v2.1.1 deprecado)
PPTX
Introduction to SAP Business One HANA
PDF
우아한테크세미나-우아한멀티모듈
PDF
GRC 5.3 to 10 upgrade.pdf
PPTX
React js programming concept
PPTX
Getting started with Redux js
PDF
UDA-Componentes RUP. Fecha
Sap ehp6 to ehp7 upgradation projects
UDA-Componentes RUP. Mantenimiento (v2.1.1 deprecado)
Introduction to SAP Business One HANA
우아한테크세미나-우아한멀티모듈
GRC 5.3 to 10 upgrade.pdf
React js programming concept
Getting started with Redux js
UDA-Componentes RUP. Fecha

What's hot (13)

PDF
DATABASE AUTOMATION with Thousands of database, monitoring and backup
PDF
62620940 charm-configuration-procedures
PPTX
Introduction to react js
PDF
Financial Planning/Budgeting Review and Approval Process in SAP BPC NW 7.5 - ...
PDF
ES6: The Awesome Parts
PPTX
Introduction to es6
PPTX
나의 이직 이야기
PDF
Introduction to Drupal Basics
PPTX
Sap lama presentation
PDF
Data migration methodology for sap v2
PPTX
Single page application
PPTX
Oracle sharding : Installation & Configuration
PDF
react redux.pdf
DATABASE AUTOMATION with Thousands of database, monitoring and backup
62620940 charm-configuration-procedures
Introduction to react js
Financial Planning/Budgeting Review and Approval Process in SAP BPC NW 7.5 - ...
ES6: The Awesome Parts
Introduction to es6
나의 이직 이야기
Introduction to Drupal Basics
Sap lama presentation
Data migration methodology for sap v2
Single page application
Oracle sharding : Installation & Configuration
react redux.pdf
Ad

Similar to A quick tour of Mysql 8 roles (20)

PDF
Mysqlsecurityoptionsjan2021
PDF
Mysqldbatrainingsession12privilegesinmysql 170302152348
PDF
MySQL 8.0 : Roles
PDF
Mysql nowwhat
PPTX
Write the query for creating the users exp 11
PDF
Security in ORACLE RDBMS
PDF
Rootconf admin101
PDF
SULTHAN's PHP, MySQL & wordpress
PDF
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
PDF
Lecture Notes Unit4 Chapter13 users , roles and privileges
PDF
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
PPTX
DBMS: Week 15 - Database Security and Access Control
PDF
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
PDF
Introduction to MariaDb
PPTX
User Information in Oracle introduction.pptx
PDF
Managing a shared mysql farm dpc11
PPTX
Clase 19 roles modificada
PPTX
Clase 19 roles modificada
PDF
Basic MySQL Troubleshooting for Oracle DBAs
Mysqlsecurityoptionsjan2021
Mysqldbatrainingsession12privilegesinmysql 170302152348
MySQL 8.0 : Roles
Mysql nowwhat
Write the query for creating the users exp 11
Security in ORACLE RDBMS
Rootconf admin101
SULTHAN's PHP, MySQL & wordpress
MySQL USER MANAGEMENT,ROUTINES & TRIGGERS.
Lecture Notes Unit4 Chapter13 users , roles and privileges
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
DBMS: Week 15 - Database Security and Access Control
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
Introduction to MariaDb
User Information in Oracle introduction.pptx
Managing a shared mysql farm dpc11
Clase 19 roles modificada
Clase 19 roles modificada
Basic MySQL Troubleshooting for Oracle DBAs
Ad

More from Giuseppe Maxia (20)

PDF
MySQL NDB 8.0 clusters in your laptop with dbdeployer
PDF
Test like a_boss
PDF
Dbdeployer, the universal installer
PDF
Test complex database systems in your laptop with dbdeployer
PDF
Dbdeployer
PDF
Dbdeployer
PDF
MySQL document_store
PDF
Replication skeptic
PDF
Synchronise your data between MySQL and MongoDB
PDF
Juggle your data with Tungsten Replicator
PDF
MySQL in your laptop
PDF
Script it
PDF
Tungsten Replicator tutorial
PDF
Preventing multi master conflicts with tungsten
PDF
MySQL high availability power and usability
PDF
Solving MySQL replication problems with Tungsten
PDF
State of the art of MySQL replication and clustering
PDF
Testing mysql creatively in a sandbox
PDF
Mysql 5.5 and 5.6 replication
PDF
Lightning talks percona live mysql_2012
MySQL NDB 8.0 clusters in your laptop with dbdeployer
Test like a_boss
Dbdeployer, the universal installer
Test complex database systems in your laptop with dbdeployer
Dbdeployer
Dbdeployer
MySQL document_store
Replication skeptic
Synchronise your data between MySQL and MongoDB
Juggle your data with Tungsten Replicator
MySQL in your laptop
Script it
Tungsten Replicator tutorial
Preventing multi master conflicts with tungsten
MySQL high availability power and usability
Solving MySQL replication problems with Tungsten
State of the art of MySQL replication and clustering
Testing mysql creatively in a sandbox
Mysql 5.5 and 5.6 replication
Lightning talks percona live mysql_2012

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Monthly Chronicles - July 2025
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks

A quick tour of Mysql 8 roles

  • 1. A quick tour of MySQL 8.0 roles Giuseppe Maxia Software explorer !1 @datacharmer #dataopsbarcelona
  • 2. Who's this guy? About me ‣ Giuseppe Maxia, a.k.a. "The Data Charmer" ‣ Software Explorer at VMware ‣ Several decades development and DB experience ‣ Long timer MySQL community member. ‣ Blog: http://datacharmer.blogspot.com ‣ Twitter: @datacharmer !2
  • 3. Disclaimer •None of what I say has anything to do with my company. •I also don’t work for Oracle.
  • 4. A long coveted feature finally arrives Roles overview ‣ Available since MySQL 8.0.0 ‣ Created like an user ‣ Granted like privileges ‣ Need to be activated (with tricks) !4
  • 5. Up until the current GA (MySQL 5.7) there were no roles Before roles ‣ CREATE USER ‣ GRANT, GRANT, and more granular GRANT ‣ CREATE USER ‣ GRANT, GRANT again, and then GRANT ‣ CREATE USER ‣ GRANT, GRANT, GRANT, GRANT, oops! !5 In short: a lot of work, with many chances to make mistakes
  • 6. Why bother with this new feature? Advantages of roles ‣ Faster user administration • define a role once • assign it many times ‣ Centralised grants handling • grant and revoke privileges to roles • No need to edit all users profiles ‣ Easy to understand grants statistics !6
  • 7. A BAD example. (1) !7 So far, so good
  • 8. A BAD example. (2) !8 WHAT DID JUST HAPPEN ? STAY TUNED TO FIND OUT
  • 9. !9 Roles usage 1CREATE ROLE 3CREATE USER 2 GRANT PRIVILEGES to ROLE 4GRANT ROLE TO USER 5SET (DEFAULT) ROLE
  • 10. Like creating a user Create role CREATE ROLE r_lotr_dev; ## NOTE: there is no "IDENTIFIED" clause !10
  • 11. Same as we do it with users grant privileges to role GRANT ALL ON lotr.* TO r_lotr_dev; !11
  • 12. This one is already known Create user CREATE USER aragorn IDENTIFIED BY 'lotrpwd'; !12
  • 13. We grant a role in a way similar to granting a privilege Grant role to user GRANT r_lotr_dev TO aragorn; ## NOTE: there is not an "ON" clause ## in the GRANT statement. !13
  • 14. The role needs to be activate Set [default] role ALTER USER aragorn DEFAULT ROLE r_lotr_dba; ## OR SET DEFAULT ROLE r_lotr_dba TO aragorn; !14 There is more than one way to do it Unfortunately
  • 16. Grants are the total of all roles privileges A user can be granted more roles ‣ User can have many roles ‣ The default role can be a list of roles !16
  • 17. This may cause some confusion Roles are saved in 'user' table ‣ Roles are users without login (= account locked and expired password) !17
  • 18. It is there, but you can't see it Granting a role to a user is not enough ‣ When we grant a privilege, the user can use it immediately. ‣ When we grant a role, we first need to set the default. !18
  • 19. This may look tricky, but it is really simple We can grant a user to a user ‣ Roles are users without login ‣ But roles with login (i.e. users) can be granted. ‣ Privileges are assigned regardless of the host of the user. GRANT root@'localhost' to someuser; ‣ user someuser@'%' has all privileges of root from any host !19
  • 20. You can lose track easily here SET ROLE anyone? ‣ SET ROLE role_name is a session assignment of a role ‣ SET DEFAULT ROLE role_name is a permanent assignment of a role for a user ‣ SET ROLE DEFAULT means assign the default role to this user for the session. !20
  • 21. Sadly, it's up to the DBA's ingenuity Telling roles from users ‣ Roles are users with expired password and locked account. ‣ A good workaround is using a naming convention to tell roles apart (e.g. "r_something") !21 There is a feature request about this matter, but I haven’t seen any progress on it.
  • 22. We have two new tables in 'mysql' DB dedicated to roles Tables for roles ‣ role_edges reports which roles are assigned to which users. ‣ default_roles takes track of the current default roles assigned to users. !22
  • 25. !25 Create users and apply roles
  • 31. !31 Who are the developers?
  • 37. !37 SET ROLE is not permanent
  • 38. Back to the BAD example. (2) !38
  • 39. Back to the BAD example. (3) !39
  • 40. It’s a all-or-nothing option Roles can be active by default ‣ Starting in 8.0.2 ‣ You can use option activate_all_roles_on_login • When enabled, all roles become active by default ‣ And mandatory_roles • When set, all users will get the role(s) defined !40
  • 41. Example with mandatory roles (1) mysql> create schema lotr; Query OK, 1 row affected (0.00 sec) mysql> grant select on lotr.* to r_lotr_reader; Query OK, 0 rows affected (0.00 sec) mysql> set global mandatory_roles='r_lotr_reader'; Query OK, 0 rows affected (0.00 sec) mysql> create user dummy identified by 'msandbox'; Query OK, 0 rows affected (0.00 sec) !41
  • 42. Example with mandatory roles (2) $ mysql lotr -u dummy -p ERROR 1044 (42000): Access denied for user 'dummy'@'%' to database ‘lotr' # ====== as root ======== mysql> set global activate_all_roles_on_login=1; $ mysql lotr -u dummy -p mysql> show grants; +------------------------------------------+ | Grants for dummy@% | +------------------------------------------+ | GRANT USAGE ON *.* TO `dummy`@`%` | | GRANT SELECT ON `lotr`.* TO `dummy`@`%` | | GRANT `r_lotr_reader`@`%` TO `dummy`@`%` | +------------------------------------------+ 3 rows in set (0.00 sec) !42
  • 43. Example with mandatory roles (3) $ mysql lotr -u root -p mysql> show grantsG *** 1. row *** Grants for root@localhost: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION *** 2. row *** Grants for root@localhost: GRANT BACKUP_ADMIN,BINLOG_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,GROUP_REPL ICATION_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_SLAVE_ADMIN,RESOURCE_ GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SET_USER_ID,SYSTEM_VARIABLES_AD MIN,XA_RECOVER_ADMIN ON *.* TO `root`@`localhost` WITH GRANT OPTION *** 3. row *** Grants for root@localhost: GRANT SELECT ON `lotr`.* TO `root`@`localhost` !43
  • 44. Roles are a great feature, but they could be better Wish list ‣ Missing information_schema (or sys) views • List of global roles • List of roles enabled for the current session • List of default roles • List of users for a given role ‣ Roles active by default !44
  • 45. Latest additions ‣ In 8.0.3+ ‣ You can set the default role within CREATE USER. !45