SlideShare a Scribd company logo
Frédéric Descamps
Community Manager
MySQL
February 2021
MySQL Router
REST API
Who am I ?
about.me/lefred
Copyright @ 2021 Oracle and/or its affiliates.
2
Frédéric Descamps
@lefred
MySQL Evangelist
Managing MySQL since 3.20
devops believer
living in Belgium
h ps://lefred.be
Copyright @ 2021 Oracle and/or its affiliates.
3
What is it ?
MySQL Router
Copyright @ 2021 Oracle and/or its affiliates.
4
MySQL Router
MySQL Router is a building block for high availability (HA) solutions. It simpli es application
development by intelligently routing connections to MySQL servers for increased
performance and reliability.
MySQL Router is part of MySQL InnoDB Cluster and MySQL InnoDB ReplicaSet.
MySQL Router is wri ent in C++ and is part of MySQL's trunk.
Copyright @ 2021 Oracle and/or its affiliates.
5
MySQL Router
REST API
Copyright @ 2021 Oracle and/or its affiliates.
6
MySQL Router REST API - Why ?
When a problem occurs, it's not always obvious to understand why ? For example if for a
given route, the amount of max_connections is reached, it's important to know it and to
know that value before we reach it.
MySQL Router exposes data (statistics, se ings, ..,) as REST endpoints via HTTP methods
as JSON payload.
This is explained in WL#8965.
Copyright @ 2021 Oracle and/or its affiliates.
7
MySQL Router REST API - How ?
Since MySQL 8.0.16, MySQL Router has the possibility to launch an internal h p server. At
that time it could only serve static les.
Then, in MySQL 8.0.17 we added the REST API to MySQL Router.
With MySQL 8.0.20 the authentication credentials to access the REST API could also be
stored on MySQL in a metadata table, before it was only using a le. See WL#12952.
And nally with MySQL 8.0.22, bootstrapping a MySQL Router also con gures the REST
API functionality into the generated mysqlrouter.conf con guration le.
Copyright @ 2021 Oracle and/or its affiliates.
8
Test it and get the paths
To query swagger.json no authentication is required:
Copyright @ 2021 Oracle and/or its affiliates.
9
MySQL Router REST API - Authentication
MySQL Router uses realms for authentication. The backend can be a le or a record in a
metadata table:
[http_auth_backend:default_auth_backend]
backend=metadata_cache
If you use a le, the mysqlrouter_passwd command-line utility must be used to generate
and manage the users.
Copyright @ 2021 Oracle and/or its affiliates.
10
MySQL Router REST API - Authentication (metadata)
So there is a table in the metadata that we can use to connect to the REST API. Let's have a
look...
Copyright @ 2021 Oracle and/or its affiliates.
11
MySQL Router REST API - Authentication (metadata)
So there is a table in the metadata that we can use to connect to the REST API. Let's have a
look...
Copyright @ 2021 Oracle and/or its affiliates.
11
MySQL Router REST API - Authentication (metadata)
So there is a table in the metadata that we can use to connect to the REST API. Let's have a
look...
So when we bootstrap a Router against a MySQL InnoDB Cluster or a MySQL InnoDB
ReplicaSet, we need to add a user in this table.
Copyright @ 2021 Oracle and/or its affiliates.
11
My journey to add a user in router_rest_accounts
Let me share with you my journey to insert a user into that table...
Copyright @ 2021 Oracle and/or its affiliates.
12
My journey to add a user in router_rest_accounts
Let me share with you my journey to insert a user into that table...
Copyright @ 2021 Oracle and/or its affiliates.
12
Adding a user in router_rest_accounts - A empt #1
Let's try:
INSERT INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format", "fosdem", NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
13
Adding a user in router_rest_accounts - A empt #1
Let's try:
INSERT INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format", "fosdem", NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
13
Adding a user in router_rest_accounts - A empt #1
Let's try:
INSERT INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format", "fosdem", NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
13
lefred - security : 0 - 1
Copyright @ 2021 Oracle and/or its affiliates.
14
Adding a user in router_rest_accounts - A empt #2
For my second a empt, I asked to the router dev team for an example of string I could use.
The reply was simple 'copy' the value of your authentication_string column in the
mysql.user:
Copyright @ 2021 Oracle and/or its affiliates.
15
Adding a user in router_rest_accounts - A empt #2
For my second a empt, I asked to the router dev team for an example of string I could use.
The reply was simple 'copy' the value of your authentication_string column in the
mysql.user:
REPLACE INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format",
(SELECT authentication_string FROM mysql.user WHERE user='clusteradmin'),
NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
15
Adding a user in router_rest_accounts - A empt #2
Let's test it:
Copyright @ 2021 Oracle and/or its affiliates.
16
Adding a user in router_rest_accounts - A empt #2
Let's test it:
It works... but I don't want to use a MySQL user to monitor Router !
Copyright @ 2021 Oracle and/or its affiliates.
16
Adding a user in router_rest_accounts - A empt #2
Let's test it:
It works... but I don't want to use a MySQL user to monitor Router !
It's important to provide accurate information and context when you ask something...
Copyright @ 2021 Oracle and/or its affiliates.
16
lefred - developer : 0 - 1
Copyright @ 2021 Oracle and/or its affiliates.
17
Adding a user in router_rest_accounts - A empt #3
My goal was to manage the credential for the REST API using a MySQL Shell Plugin...
I've been said that I should use the same string as a MySQL user... let's generate it !
Copyright @ 2021 Oracle and/or its affiliates.
18
Adding a user in router_rest_accounts - A empt #3
My goal was to manage the credential for the REST API using a MySQL Shell Plugin...
I've been said that I should use the same string as a MySQL user... let's generate it !
I created a program that does it:
Copyright @ 2021 Oracle and/or its affiliates.
18
Adding a user in router_rest_accounts - A empt #3
My goal was to manage the credential for the REST API using a MySQL Shell Plugin...
I've been said that I should use the same string as a MySQL user... let's generate it !
I created a program that does it:
REPLACE INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format",
'$A$005$zwM4!A72%s)](-ed8FN-euE7cwRygTogySEBOTQY46UbIU483McwXJYiovTbML2',
NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
18
Adding a user in router_rest_accounts - A empt #3
Let's test it:
Copyright @ 2021 Oracle and/or its affiliates.
19
Adding a user in router_rest_accounts - A empt #3
Let's test it:
It works... but I don't want to use an external program in my plugin, that's not very portable.
Copyright @ 2021 Oracle and/or its affiliates.
19
lefred - usability : 0 - 1
Copyright @ 2021 Oracle and/or its affiliates.
20
Adding a user in router_rest_accounts - A empt #4
Mmm... let's try something else...
Copyright @ 2021 Oracle and/or its affiliates.
21
Adding a user in router_rest_accounts - A empt #4
Mmm... let's try something else...
A component !
Copyright @ 2021 Oracle and/or its affiliates.
21
Adding a user in router_rest_accounts - A empt #4
Mmm... let's try something else...
A component !
Copyright @ 2021 Oracle and/or its affiliates.
21
Adding a user in router_rest_accounts - A empt #4
Mmm... let's try something else...
A component !
REPLACE INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format",
"$A$005$op^'U#+}b)!n*~~3E<{+Pzrzs/Rg9jUO.b4iMY56vET9E3rt2bws/BVw43zpTW8",
NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
21
Adding a user in router_rest_accounts - A empt #4
Let's test it again:
Copyright @ 2021 Oracle and/or its affiliates.
22
Adding a user in router_rest_accounts - A empt #4
Let's test it again:
It works... but again, another component needs to be installed and maintained...
Copyright @ 2021 Oracle and/or its affiliates.
22
lefred - usability : 0 - 2
Copyright @ 2021 Oracle and/or its affiliates.
23
Adding a user in router_rest_accounts - A empt #5
What else ?
Copyright @ 2021 Oracle and/or its affiliates.
24
Adding a user in router_rest_accounts - A empt #5
What else ?
Let me ask again with more context to the MySQL Router Development Team...
Copyright @ 2021 Oracle and/or its affiliates.
24
Adding a user in router_rest_accounts - A empt #5
What else ?
Let me ask again with more context to the MySQL Router Development Team...
Summary of the answer: we do support MySQL 8.0's default authentication string but also
modular_crypt_format for MCF style password hashes as speci ed in the WL...
Copyright @ 2021 Oracle and/or its affiliates.
24
Adding a user in router_rest_accounts - A empt #5
What else ?
Let me ask again with more context to the MySQL Router Development Team...
Summary of the answer: we do support MySQL 8.0's default authentication string but also
modular_crypt_format for MCF style password hashes as speci ed in the WL...
Oups...
Copyright @ 2021 Oracle and/or its affiliates.
24
Adding a user in router_rest_accounts - A empt #5
What else ?
Let me ask again with more context to the MySQL Router Development Team...
Summary of the answer: we do support MySQL 8.0's default authentication string but also
modular_crypt_format for MCF style password hashes as speci ed in the WL...
Oups...
This means that the standard Python crypt module is what I need !
Copyright @ 2021 Oracle and/or its affiliates.
24
lefred - developer : 0 - 2
Copyright @ 2021 Oracle and/or its affiliates.
25
Adding a user in router_rest_accounts - A empt #5
REPLACE INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format",
"$5$tzRKNfEyehq1B5/Q$/PlKjs6PCEjNFiSDtdVZV2aL666SZrvKvrMWfYkIO82",
NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
26
Adding a user in router_rest_accounts - A empt #5
REPLACE INTO router_rest_accounts VALUES (
(SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1),
"lefred", "modular_crypt_format",
"$5$tzRKNfEyehq1B5/Q$/PlKjs6PCEjNFiSDtdVZV2aL666SZrvKvrMWfYkIO82",
NULL, NULL, NULL);
Copyright @ 2021 Oracle and/or its affiliates.
26
Wooohooo o/
Copyright @ 2021 Oracle and/or its affiliates.
27
Examples
MySQL Router REST API
Copyright @ 2021 Oracle and/or its affiliates.
28
Some examples
We can now use the REST API with curl and include that in any montiroring tool like Sensu,
Icinga...
Copyright @ 2021 Oracle and/or its affiliates.
29
MySQL Router & MySQL Shell
With MySQL Shell's router plugin (h ps://github.com/lefred/mysqlshell-plugins), you can
take bene t of all this.
Copyright @ 2021 Oracle and/or its affiliates.
30
MySQL Router & MySQL Shell
With MySQL Shell's router plugin (h ps://github.com/lefred/mysqlshell-plugins), you can
take bene t of all this.
Creating a user for the REST API:
Copyright @ 2021 Oracle and/or its affiliates.
30
MySQL Router & MySQL Shell
With MySQL Shell's router plugin (h ps://github.com/lefred/mysqlshell-plugins), you can
take bene t of all this.
Creating a user for the REST API:
Much easier ;) Convenient++
Copyright @ 2021 Oracle and/or its affiliates.
30
MySQL Router & MySQL Shell
Creating the Router object:
Copyright @ 2021 Oracle and/or its affiliates.
31
MySQL Router & MySQL Shell
Copyright @ 2021 Oracle and/or its affiliates.
32
MySQL Router & MySQL Shell
We have an host blocked by MySQL Router, which one is it ?
Copyright @ 2021 Oracle and/or its affiliates.
33
MySQL Router & MySQL Shell
We have an host blocked by MySQL Router, which one is it ?
Copyright @ 2021 Oracle and/or its affiliates.
33
MySQL Router & MySQL Shell
And nally the routing statistics:
Copyright @ 2021 Oracle and/or its affiliates.
34
Questions ?
Copyright @ 2021 Oracle and/or its affiliates.
35

More Related Content

PDF
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
PDF
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
PDF
MySQL Connectors 8.0.19 & DNS SRV
PDF
MySQL Shell for DBAs
PDF
State of the Dolphin - May 2022
PDF
Percona Live 2022 - MySQL Architectures
PDF
MySQL Database Architectures - 2022-08
PDF
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL InnoDB Cluster - New Features in 8.0 Releases - Best Practices
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
MySQL Connectors 8.0.19 & DNS SRV
MySQL Shell for DBAs
State of the Dolphin - May 2022
Percona Live 2022 - MySQL Architectures
MySQL Database Architectures - 2022-08
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11

What's hot (20)

PDF
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
PDF
MySQL Shell - The Best MySQL DBA Tool
PDF
MySQL InnoDB Cluster HA Overview & Demo
PDF
MySQL Database Architectures - High Availability and Disaster Recovery Solution
PDF
MySQL Database Architectures - 2020-10
PDF
MySQL Group Replication: Handling Network Glitches - Best Practices
PDF
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
PDF
How to operate MySQL InnoDB Cluster with MySQL Shell
PDF
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
PDF
MySQL Replication Performance in the Cloud
PDF
Node.js and the MySQL Document Store
PDF
MySQL InnoDB Cluster - Advanced Configuration & Operations
PDF
MySQL User Group NL - MySQL 8
PDF
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
PDF
MySQL InnoDB Cluster / ReplicaSet - Making Provisioning & Troubleshooting as ...
PPTX
MySQL Performance Schema in MySQL 8.0
PDF
Percona Live 2022 - The Evolution of a MySQL Database System
PPTX
Query logging with proxysql
PDF
[2018] MySQL 이중화 진화기
ODP
Introduction to Red Hat
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
MySQL Shell - The Best MySQL DBA Tool
MySQL InnoDB Cluster HA Overview & Demo
MySQL Database Architectures - High Availability and Disaster Recovery Solution
MySQL Database Architectures - 2020-10
MySQL Group Replication: Handling Network Glitches - Best Practices
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
How to operate MySQL InnoDB Cluster with MySQL Shell
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL Replication Performance in the Cloud
Node.js and the MySQL Document Store
MySQL InnoDB Cluster - Advanced Configuration & Operations
MySQL User Group NL - MySQL 8
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
MySQL InnoDB Cluster / ReplicaSet - Making Provisioning & Troubleshooting as ...
MySQL Performance Schema in MySQL 8.0
Percona Live 2022 - The Evolution of a MySQL Database System
Query logging with proxysql
[2018] MySQL 이중화 진화기
Introduction to Red Hat
Ad

Similar to MySQL Router REST API (20)

PDF
Introduction to MariaDb
PDF
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
PDF
Better encryption & security with MariaDB 10.1 & MySQL 5.7
PDF
MySQL Router - Explore The Secrets (MySQL Belgian Days 2024)
PDF
MariaDB Server & MySQL Security Essentials 2016
PDF
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
PDF
MySQL User Camp : MySQL-Router
PDF
My sql router
PDF
MySQL 8.0 InnoDB Cluster demo
PDF
Mysqlsecurityoptionsjan2021
PDF
Managing a shared mysql farm dpc11
PDF
Rootconf admin101
PDF
Less passwords, more security: unix socket authentication and other MariaDB h...
PDF
My SQL 101
PPTX
PHP FUNCTIONS
PDF
Mysql nowwhat
PDF
High Availability in MySQL 8 using InnoDB Cluster
PDF
MySQL HA
PDF
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
PDF
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
Introduction to MariaDb
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Better encryption & security with MariaDB 10.1 & MySQL 5.7
MySQL Router - Explore The Secrets (MySQL Belgian Days 2024)
MariaDB Server & MySQL Security Essentials 2016
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL User Camp : MySQL-Router
My sql router
MySQL 8.0 InnoDB Cluster demo
Mysqlsecurityoptionsjan2021
Managing a shared mysql farm dpc11
Rootconf admin101
Less passwords, more security: unix socket authentication and other MariaDB h...
My SQL 101
PHP FUNCTIONS
Mysql nowwhat
High Availability in MySQL 8 using InnoDB Cluster
MySQL HA
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
Ad

More from Frederic Descamps (20)

PDF
MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
PDF
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
PDF
RivieraJUG - MySQL Indexes and Histograms
PDF
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
PDF
Percona Live 2022 - MySQL Shell for Visual Studio Code
PDF
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
PDF
Open Source 101 2022 - MySQL Indexes and Histograms
PDF
Pi Day 2022 - from IoT to MySQL HeatWave Database Service
PDF
Confoo 2022 - le cycle d'une instance MySQL
PDF
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
PDF
Les nouveautés de MySQL 8.0
PDF
Les nouveautés de MySQL 8.0
PDF
State of The Dolphin - May 2021
PDF
Deploying Magento on OCI with MDS
PDF
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
PDF
Cloud native - Why to use MySQL 8.0 and how to use it on oci with MDS
PDF
MySQL Database Service Webinar: Installing Drupal in oci with mds
PDF
the State of the Dolphin - October 2020
PDF
MySQL 8.0 Document Store - Discovery of a New World
PDF
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform
MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
RivieraJUG - MySQL Indexes and Histograms
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
Percona Live 2022 - MySQL Shell for Visual Studio Code
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
Open Source 101 2022 - MySQL Indexes and Histograms
Pi Day 2022 - from IoT to MySQL HeatWave Database Service
Confoo 2022 - le cycle d'une instance MySQL
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0
State of The Dolphin - May 2021
Deploying Magento on OCI with MDS
From single MySQL instance to High Availability: the journey to MySQL InnoDB ...
Cloud native - Why to use MySQL 8.0 and how to use it on oci with MDS
MySQL Database Service Webinar: Installing Drupal in oci with mds
the State of the Dolphin - October 2020
MySQL 8.0 Document Store - Discovery of a New World
Oracle Developer Live: Deploying MySQL InnoDB Cluster on OCI with Terraform

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Spectroscopy.pptx food analysis technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Electronic commerce courselecture one. Pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Machine learning based COVID-19 study performance prediction
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The Rise and Fall of 3GPP – Time for a Sabbatical?
“AI and Expert System Decision Support & Business Intelligence Systems”
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Spectroscopy.pptx food analysis technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
Review of recent advances in non-invasive hemoglobin estimation

MySQL Router REST API

  • 2. Who am I ? about.me/lefred Copyright @ 2021 Oracle and/or its affiliates. 2
  • 3. Frédéric Descamps @lefred MySQL Evangelist Managing MySQL since 3.20 devops believer living in Belgium h ps://lefred.be Copyright @ 2021 Oracle and/or its affiliates. 3
  • 4. What is it ? MySQL Router Copyright @ 2021 Oracle and/or its affiliates. 4
  • 5. MySQL Router MySQL Router is a building block for high availability (HA) solutions. It simpli es application development by intelligently routing connections to MySQL servers for increased performance and reliability. MySQL Router is part of MySQL InnoDB Cluster and MySQL InnoDB ReplicaSet. MySQL Router is wri ent in C++ and is part of MySQL's trunk. Copyright @ 2021 Oracle and/or its affiliates. 5
  • 6. MySQL Router REST API Copyright @ 2021 Oracle and/or its affiliates. 6
  • 7. MySQL Router REST API - Why ? When a problem occurs, it's not always obvious to understand why ? For example if for a given route, the amount of max_connections is reached, it's important to know it and to know that value before we reach it. MySQL Router exposes data (statistics, se ings, ..,) as REST endpoints via HTTP methods as JSON payload. This is explained in WL#8965. Copyright @ 2021 Oracle and/or its affiliates. 7
  • 8. MySQL Router REST API - How ? Since MySQL 8.0.16, MySQL Router has the possibility to launch an internal h p server. At that time it could only serve static les. Then, in MySQL 8.0.17 we added the REST API to MySQL Router. With MySQL 8.0.20 the authentication credentials to access the REST API could also be stored on MySQL in a metadata table, before it was only using a le. See WL#12952. And nally with MySQL 8.0.22, bootstrapping a MySQL Router also con gures the REST API functionality into the generated mysqlrouter.conf con guration le. Copyright @ 2021 Oracle and/or its affiliates. 8
  • 9. Test it and get the paths To query swagger.json no authentication is required: Copyright @ 2021 Oracle and/or its affiliates. 9
  • 10. MySQL Router REST API - Authentication MySQL Router uses realms for authentication. The backend can be a le or a record in a metadata table: [http_auth_backend:default_auth_backend] backend=metadata_cache If you use a le, the mysqlrouter_passwd command-line utility must be used to generate and manage the users. Copyright @ 2021 Oracle and/or its affiliates. 10
  • 11. MySQL Router REST API - Authentication (metadata) So there is a table in the metadata that we can use to connect to the REST API. Let's have a look... Copyright @ 2021 Oracle and/or its affiliates. 11
  • 12. MySQL Router REST API - Authentication (metadata) So there is a table in the metadata that we can use to connect to the REST API. Let's have a look... Copyright @ 2021 Oracle and/or its affiliates. 11
  • 13. MySQL Router REST API - Authentication (metadata) So there is a table in the metadata that we can use to connect to the REST API. Let's have a look... So when we bootstrap a Router against a MySQL InnoDB Cluster or a MySQL InnoDB ReplicaSet, we need to add a user in this table. Copyright @ 2021 Oracle and/or its affiliates. 11
  • 14. My journey to add a user in router_rest_accounts Let me share with you my journey to insert a user into that table... Copyright @ 2021 Oracle and/or its affiliates. 12
  • 15. My journey to add a user in router_rest_accounts Let me share with you my journey to insert a user into that table... Copyright @ 2021 Oracle and/or its affiliates. 12
  • 16. Adding a user in router_rest_accounts - A empt #1 Let's try: INSERT INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", "fosdem", NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 13
  • 17. Adding a user in router_rest_accounts - A empt #1 Let's try: INSERT INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", "fosdem", NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 13
  • 18. Adding a user in router_rest_accounts - A empt #1 Let's try: INSERT INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", "fosdem", NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 13
  • 19. lefred - security : 0 - 1 Copyright @ 2021 Oracle and/or its affiliates. 14
  • 20. Adding a user in router_rest_accounts - A empt #2 For my second a empt, I asked to the router dev team for an example of string I could use. The reply was simple 'copy' the value of your authentication_string column in the mysql.user: Copyright @ 2021 Oracle and/or its affiliates. 15
  • 21. Adding a user in router_rest_accounts - A empt #2 For my second a empt, I asked to the router dev team for an example of string I could use. The reply was simple 'copy' the value of your authentication_string column in the mysql.user: REPLACE INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", (SELECT authentication_string FROM mysql.user WHERE user='clusteradmin'), NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 15
  • 22. Adding a user in router_rest_accounts - A empt #2 Let's test it: Copyright @ 2021 Oracle and/or its affiliates. 16
  • 23. Adding a user in router_rest_accounts - A empt #2 Let's test it: It works... but I don't want to use a MySQL user to monitor Router ! Copyright @ 2021 Oracle and/or its affiliates. 16
  • 24. Adding a user in router_rest_accounts - A empt #2 Let's test it: It works... but I don't want to use a MySQL user to monitor Router ! It's important to provide accurate information and context when you ask something... Copyright @ 2021 Oracle and/or its affiliates. 16
  • 25. lefred - developer : 0 - 1 Copyright @ 2021 Oracle and/or its affiliates. 17
  • 26. Adding a user in router_rest_accounts - A empt #3 My goal was to manage the credential for the REST API using a MySQL Shell Plugin... I've been said that I should use the same string as a MySQL user... let's generate it ! Copyright @ 2021 Oracle and/or its affiliates. 18
  • 27. Adding a user in router_rest_accounts - A empt #3 My goal was to manage the credential for the REST API using a MySQL Shell Plugin... I've been said that I should use the same string as a MySQL user... let's generate it ! I created a program that does it: Copyright @ 2021 Oracle and/or its affiliates. 18
  • 28. Adding a user in router_rest_accounts - A empt #3 My goal was to manage the credential for the REST API using a MySQL Shell Plugin... I've been said that I should use the same string as a MySQL user... let's generate it ! I created a program that does it: REPLACE INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", '$A$005$zwM4!A72%s)](-ed8FN-euE7cwRygTogySEBOTQY46UbIU483McwXJYiovTbML2', NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 18
  • 29. Adding a user in router_rest_accounts - A empt #3 Let's test it: Copyright @ 2021 Oracle and/or its affiliates. 19
  • 30. Adding a user in router_rest_accounts - A empt #3 Let's test it: It works... but I don't want to use an external program in my plugin, that's not very portable. Copyright @ 2021 Oracle and/or its affiliates. 19
  • 31. lefred - usability : 0 - 1 Copyright @ 2021 Oracle and/or its affiliates. 20
  • 32. Adding a user in router_rest_accounts - A empt #4 Mmm... let's try something else... Copyright @ 2021 Oracle and/or its affiliates. 21
  • 33. Adding a user in router_rest_accounts - A empt #4 Mmm... let's try something else... A component ! Copyright @ 2021 Oracle and/or its affiliates. 21
  • 34. Adding a user in router_rest_accounts - A empt #4 Mmm... let's try something else... A component ! Copyright @ 2021 Oracle and/or its affiliates. 21
  • 35. Adding a user in router_rest_accounts - A empt #4 Mmm... let's try something else... A component ! REPLACE INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", "$A$005$op^'U#+}b)!n*~~3E<{+Pzrzs/Rg9jUO.b4iMY56vET9E3rt2bws/BVw43zpTW8", NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 21
  • 36. Adding a user in router_rest_accounts - A empt #4 Let's test it again: Copyright @ 2021 Oracle and/or its affiliates. 22
  • 37. Adding a user in router_rest_accounts - A empt #4 Let's test it again: It works... but again, another component needs to be installed and maintained... Copyright @ 2021 Oracle and/or its affiliates. 22
  • 38. lefred - usability : 0 - 2 Copyright @ 2021 Oracle and/or its affiliates. 23
  • 39. Adding a user in router_rest_accounts - A empt #5 What else ? Copyright @ 2021 Oracle and/or its affiliates. 24
  • 40. Adding a user in router_rest_accounts - A empt #5 What else ? Let me ask again with more context to the MySQL Router Development Team... Copyright @ 2021 Oracle and/or its affiliates. 24
  • 41. Adding a user in router_rest_accounts - A empt #5 What else ? Let me ask again with more context to the MySQL Router Development Team... Summary of the answer: we do support MySQL 8.0's default authentication string but also modular_crypt_format for MCF style password hashes as speci ed in the WL... Copyright @ 2021 Oracle and/or its affiliates. 24
  • 42. Adding a user in router_rest_accounts - A empt #5 What else ? Let me ask again with more context to the MySQL Router Development Team... Summary of the answer: we do support MySQL 8.0's default authentication string but also modular_crypt_format for MCF style password hashes as speci ed in the WL... Oups... Copyright @ 2021 Oracle and/or its affiliates. 24
  • 43. Adding a user in router_rest_accounts - A empt #5 What else ? Let me ask again with more context to the MySQL Router Development Team... Summary of the answer: we do support MySQL 8.0's default authentication string but also modular_crypt_format for MCF style password hashes as speci ed in the WL... Oups... This means that the standard Python crypt module is what I need ! Copyright @ 2021 Oracle and/or its affiliates. 24
  • 44. lefred - developer : 0 - 2 Copyright @ 2021 Oracle and/or its affiliates. 25
  • 45. Adding a user in router_rest_accounts - A empt #5 REPLACE INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", "$5$tzRKNfEyehq1B5/Q$/PlKjs6PCEjNFiSDtdVZV2aL666SZrvKvrMWfYkIO82", NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 26
  • 46. Adding a user in router_rest_accounts - A empt #5 REPLACE INTO router_rest_accounts VALUES ( (SELECT cluster_id FROM mysql_innodb_cluster_metadata.v2_clusters LIMIT 1), "lefred", "modular_crypt_format", "$5$tzRKNfEyehq1B5/Q$/PlKjs6PCEjNFiSDtdVZV2aL666SZrvKvrMWfYkIO82", NULL, NULL, NULL); Copyright @ 2021 Oracle and/or its affiliates. 26
  • 47. Wooohooo o/ Copyright @ 2021 Oracle and/or its affiliates. 27
  • 48. Examples MySQL Router REST API Copyright @ 2021 Oracle and/or its affiliates. 28
  • 49. Some examples We can now use the REST API with curl and include that in any montiroring tool like Sensu, Icinga... Copyright @ 2021 Oracle and/or its affiliates. 29
  • 50. MySQL Router & MySQL Shell With MySQL Shell's router plugin (h ps://github.com/lefred/mysqlshell-plugins), you can take bene t of all this. Copyright @ 2021 Oracle and/or its affiliates. 30
  • 51. MySQL Router & MySQL Shell With MySQL Shell's router plugin (h ps://github.com/lefred/mysqlshell-plugins), you can take bene t of all this. Creating a user for the REST API: Copyright @ 2021 Oracle and/or its affiliates. 30
  • 52. MySQL Router & MySQL Shell With MySQL Shell's router plugin (h ps://github.com/lefred/mysqlshell-plugins), you can take bene t of all this. Creating a user for the REST API: Much easier ;) Convenient++ Copyright @ 2021 Oracle and/or its affiliates. 30
  • 53. MySQL Router & MySQL Shell Creating the Router object: Copyright @ 2021 Oracle and/or its affiliates. 31
  • 54. MySQL Router & MySQL Shell Copyright @ 2021 Oracle and/or its affiliates. 32
  • 55. MySQL Router & MySQL Shell We have an host blocked by MySQL Router, which one is it ? Copyright @ 2021 Oracle and/or its affiliates. 33
  • 56. MySQL Router & MySQL Shell We have an host blocked by MySQL Router, which one is it ? Copyright @ 2021 Oracle and/or its affiliates. 33
  • 57. MySQL Router & MySQL Shell And nally the routing statistics: Copyright @ 2021 Oracle and/or its affiliates. 34
  • 58. Questions ? Copyright @ 2021 Oracle and/or its affiliates. 35