SlideShare a Scribd company logo
1 / 111
Python and MySQL 8.0 Document
Store
DEV5966
Frédéric Descamps
Community Manager
MySQL
September 2019
2 / 111
 
Safe Harbor
The following is intended to outline our general product direction. It is intended for information purpose only, and
may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality,
and should not be relied up in making purchasing decisions. The development, release, timing and pricing of any
features or functionality described for Oracle's product may change and remains at the sole discretion of Oracle
Corporation.
Statement in this presentation relating to Oracle's future plans, expectations, beliefs, intentions and ptospects are
"forward-looking statements" and are subject to material risks and uncertainties. A detailed discussion of these
factors and other risks that a ect our business is contained in Oracle's Securities and Exchange Commission
(SEC) lings, including our most recent reports on Form 10-K and Form 10-Q under the heading "Risk Factors".
These lings are available on the SEC's website or on Oracle's website at h p://www.oracle.com/investor. All
information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any
statement in light of new information or future events.
Copyright @ 2019 Oracle and/or its affiliates.
3 / 111
about.me/lefred
Who am I ?
Copyright @ 2019 Oracle and/or its affiliates.
4 / 111
Frédéric Descamps
@lefred
MySQL Evangelist
Managing MySQL since 3.23
devops believer
living in Belgium 🇧🇪
h ps://lefred.be
Copyright @ 2019 Oracle and/or its affiliates.
5 / 111
MySQL and JSON
How MySQL works with JSON
Copyright @ 2019 Oracle and/or its affiliates.
6 / 111
JavaScript Object Notation (JSON)
{
"_id": "5ad5b645f88c5bb8fe3fd337",
"name": "Morris Park Bake Shop",
"grades": [
{
"date": "2014-03-03T00:00:00Z",
"grade": "A",
"score": 2
},
],
"address": {
"coord": [
-73.856077,
40.848447
],
"street": "Morris Park Ave",
"zipcode": "10462",
"building": "1007"
},
"borough": "Bronx",
"cuisine": "Bakery",
"restaurant_id": "30075445"
}
Copyright @ 2019 Oracle and/or its affiliates.
7 / 111
8.0
MySQL has Native JSON Support
JSON data type since MySQL 5.7
Copyright @ 2019 Oracle and/or its affiliates.
8 / 111
8.0
MySQL has Native JSON Support
JSON data type since MySQL 5.7
Stored as binary object
Copyright @ 2019 Oracle and/or its affiliates.
9 / 111
8.0
MySQL has Native JSON Support
JSON data type since MySQL 5.7
Stored as binary object
Support for partial updates in MySQL 8.0
Copyright @ 2019 Oracle and/or its affiliates.
10 / 111
8.0
MySQL has Native JSON Support
JSON data type since MySQL 5.7
Stored as binary object
Support for partial updates in MySQL 8.0
30 JSON functions
Copyright @ 2019 Oracle and/or its affiliates.
11 / 111
8.0
... and support JSON Paths
$.address.coord[*]
$ the root of the document
Copyright @ 2019 Oracle and/or its affiliates.
12 / 111
8.0
... and support JSON Paths
$.address.coord[*]
$ the root of the document
. path leg separator
Copyright @ 2019 Oracle and/or its affiliates.
13 / 111
8.0
... and support JSON Paths
$.address.coord[*]
$ the root of the document
. path leg separator
* wildcard:
Copyright @ 2019 Oracle and/or its affiliates.
14 / 111
8.0
... and support JSON Paths
$.address.coord[*]
$ the root of the document
. path leg separator
* wildcard:
.* all members in the object
[*] all values in the array
[pre x]**su x path beginning with
pre x and ending with su x
Copyright @ 2019 Oracle and/or its affiliates.
15 / 111
MySQL Document Store
the Solution
Copyright @ 2019 Oracle and/or its affiliates.
16 / 111
Built on
the MySQL
JSON Data
type and
Proven
MySQL
Server
Technology
Provides a schema exible JSON Document Store
No SQL required
No need to de ne all possible a ributes, tables, etc.
Uses new X DevAPI
Can leverage generated column to extract JSON values into
materialized columns that can be indexed for fast SQL searches.
Document can be ~1GB
It's a column in a row of a table
It cannot exceed max_allowed_packet
Allows use of modern programming styles
No more embedded strings of SQL in your code
Easy to read
Also works with relational Tables
Proven MySQL Technology
Copyright @ 2019 Oracle and/or its affiliates.
17 / 111
X Protocol Connectors
Copyright @ 2019 Oracle and/or its affiliates.
18 / 111
X DevAPI Developed from scratch for modern development
Supports:
SQL
NoSQL - JSON documents
NoSQL - SQL tables
Uniform API across programming languages
We provide connectors for
C++, Java, .Net, Node.js, Python, PHP
working with Communities to help them supporting it too
Supported in the MySQL Shell
Full ACID support
Savepoints
Connection pools (as of 8.0.13)
Copyright @ 2019 Oracle and/or its affiliates.
19 / 111
PY
JS
SQL
>
MySQL 8.0
Upgrade Checker
Auto Completion
&
Command History
Output
Formats
(table, json, tabs)
Prompt
Themes
Batch
Execution
5.7
8.0
JS
Document
Store
X dev API
SQL CLI InnoDB
Cluster
importJSON
JSJS
parallel
importTABLE
data
Copyright @ 2019 Oracle and/or its affiliates.
20 / 111
Migration from MongoDB to MySQL DS
For this example, I will use the well known restaurants collection:
Copyright @ 2019 Oracle and/or its affiliates.
21 / 111
Migration from MongoDB to MySQL DS
For this example, I will use the well known restaurants collection:
Copyright @ 2019 Oracle and/or its affiliates.
22 / 111
Copyright @ 2019 Oracle and/or its affiliates.
23 / 111
Copyright @ 2019 Oracle and/or its affiliates.
24 / 111
Let's query
Copyright @ 2019 Oracle and/or its affiliates.
25 / 111
Let's query
That's too much records to show on this slide...
Copyright @ 2019 Oracle and/or its affiliates.
26 / 111
Let's query
That's too much records to show on this slide...
Copyright @ 2019 Oracle and/or its affiliates.
27 / 111
Let's query
That's too much records to show on this slide...
Let's add a limit to it
Copyright @ 2019 Oracle and/or its affiliates.
28 / 111
 
Copyright @ 2019 Oracle and/or its affiliates.
29 / 111
Some more examples
Copyright @ 2019 Oracle and/or its affiliates.
30 / 111
Some more examples
Let's add a selection criteria:
Copyright @ 2019 Oracle and/or its affiliates.
31 / 111
Using IN...
Copyright @ 2019 Oracle and/or its affiliates.
32 / 111
Syntax slightly different than MongoDB
Copyright @ 2019 Oracle and/or its affiliates.
33 / 111
Syntax slightly different than MongoDB
Copyright @ 2019 Oracle and/or its affiliates.
34 / 111
CRUD operations
Copyright @ 2019 Oracle and/or its affiliates.
35 / 111
CRUD operations for collections
Add a document
Copyright @ 2019 Oracle and/or its affiliates.
36 / 111
CRUD operations for collections
Add a document
collection.add({ name: 'fred', age: 42 })
.add({ name: 'dave', age: 23 })
.execute()
collection.add([
{ name: 'dimo', age: 50 },
{ name: 'kenny', age: 25 }
]).execute()
Copyright @ 2019 Oracle and/or its affiliates.
37 / 111
CRUD operations for collections
Modify a document
Copyright @ 2019 Oracle and/or its affiliates.
38 / 111
CRUD operations for collections
Modify a document
collection.modify('name = :name')
.bind('name', 'fred')
.set('age', 43)
.sort('name ASC')
.limit(1)
.execute()
collection.modify('name = :name')
.bind('name', 'fred')
.patch({ age: 43, active: false })
.sort('name DESC')
.limit(1)
.execute()
Copyright @ 2019 Oracle and/or its affiliates.
39 / 111
CRUD operations for collections
Remove a document
Copyright @ 2019 Oracle and/or its affiliates.
40 / 111
CRUD operations for collections
Remove a document
collection.remove('name = :name')
.bind('name', 'fred')
.sort('age ASC')
.limit(1)
.execute()
Copyright @ 2019 Oracle and/or its affiliates.
41 / 111
MySQL Document Store Objects Summary
Copyright @ 2019 Oracle and/or its affiliates.
42 / 111
All you need to know is here:
h ps://dev.mysql.com/doc/x-devapi-userguide/en/crud-operations-overview.html
Copyright @ 2019 Oracle and/or its affiliates.
43 / 111
MySQL Connector Python
The Python connector for MySQL
Copyright @ 2019 Oracle and/or its affiliates.
44 / 111
NoSQL
SQL
 
MySQL Connector/Python 8
GA since April 2018
Copyright @ 2019 Oracle and/or its affiliates.
45 / 111
NoSQL
SQL
 
MySQL Connector/Python 8
GA since April 2018
Maintained by Oracle
Copyright @ 2019 Oracle and/or its affiliates.
46 / 111
NoSQL
SQL
 
MySQL Connector/Python 8
GA since April 2018
Maintained by Oracle
Dual license
Copyright @ 2019 Oracle and/or its affiliates.
47 / 111
NoSQL
SQL
 
MySQL Connector/Python 8
GA since April 2018
Maintained by Oracle
Dual license
Support MySQL Server 5.5, 5.6, 5.7 and 8.0
Copyright @ 2019 Oracle and/or its affiliates.
48 / 111
NoSQL
SQL
 
MySQL Connector/Python 8
GA since April 2018
Maintained by Oracle
Dual license
Support MySQL Server 5.5, 5.6, 5.7 and 8.0
SQL and NoSQL support
Copyright @ 2019 Oracle and/or its affiliates.
49 / 111
NoSQL
SQL
 
MySQL Connector/Python 8
GA since April 2018
Maintained by Oracle
Dual license
Support MySQL Server 5.5, 5.6, 5.7 and 8.0
SQL and NoSQL support
Table and JSON Document support
Copyright @ 2019 Oracle and/or its affiliates.
50 / 111
MySQL Connector/Python 8 - 3 APIs
Choice of Three APIs
API Python Module Comment
PEP249 Python Database API mysql.connector The traditional API
C Extension API _mysql_connector Similar to the MySQL C API
MySQL X DevAPI mysqlx New in 8.0, both SQL and NoSQL
 
All you need to know is here: h ps://dev.mysql.com/doc/connector-python/en/
Copyright @ 2019 Oracle and/or its affiliates.
51 / 111
 DATABASES = {
'default': {
'NAME': 'user_data',
'ENGINE': 'mysql.connector.django',
'USER': 'mysql_user',
'PASSWORD': 'password',
'OPTIONS': {
'autocommit': True,
},
}
}
MySQL Connect/Python and Django
MySQL Connector/Python includes also a mysql.connector.django module that provides a
Django back end for MySQL
Copyright @ 2019 Oracle and/or its affiliates.
52 / 111
MySQL Connector/Python 8 - installation
easiest, use pip:
use a MySQL repository for your distribution (fedora, ubuntu, debian, ...)
Copyright @ 2019 Oracle and/or its affiliates.
53 / 111
MySQL Connector/Python 8 - installation
or go to h ps://dev.mysql.com/downloads/connector/python/
Copyright @ 2019 Oracle and/or its affiliates.
54 / 111
What time is it ?
Time to code !
Copyright @ 2019 Oracle and/or its affiliates.
55 / 111
Some coding...
import mysqlx
session = mysqlx.get_session( {
'host': 'localhost', 'port': 33060,
'user': 'fred', 'password': 'fred' })
db = session.get_schema('docstore')
col = db.get_collection('all_recs')
restaurants = col. nd("cuisine='Italian'"). elds("name, cuisine, borough")
.limit(3).execute()
for restaurant in restaurants.fetch_all():
print restaurant
session.close()
Copyright @ 2019 Oracle and/or its affiliates.
56 / 111
If it was not yet obvious, you can now use
MySQL without SQL !
Copyright @ 2019 Oracle and/or its affiliates.
57 / 111
OK we have Document Store, CRUD and ACID
but what makes MySQL Document Store
unique ?
Copyright @ 2019 Oracle and/or its affiliates.
58 / 111
Challenge: list the best restaurant of each type
of food and show the top 10, with the best one
first !
 
don't forget that all these restaurants are just JSON documents
Copyright @ 2019 Oracle and/or its affiliates.
59 / 111
NoSQL as SQL - aggregation
Copyright @ 2019 Oracle and/or its affiliates.
60 / 111
NoSQL as SQL - aggregation
Copyright @ 2019 Oracle and/or its affiliates.
61 / 111
NoSQL as SQL - aggregation
Copyright @ 2019 Oracle and/or its affiliates.
62 / 111
import mysqlx
session = mysqlx.get_session( {
'host': 'localhost', 'port': 33060,
'user': 'fred', 'password': 'fred' })
db = session.get_schema('docstore')
col = db.get_collection('all_recs')
restaurants = col. nd("cuisine='Italian'"). elds("name, cuisine, borough")
.limit(3).execute()
for restaurant in restaurants.fetch_all():
print restaurant
result = session.sql('''WITH cte1 AS (SELECT doc->>"$.name" AS name,
doc->>"$.cuisine" AS cuisine,
(SELECT AVG(score) FROM JSON_TABLE(doc, "$.grades[*]"
COLUMNS (score INT PATH "$.score")) AS r) AS avg_score
FROM docstore.all_recs) SELECT *, RANK() OVER
(PARTITION BY cuisine ORDER BY avg_score DESC) AS `rank`
FROM cte1 ORDER BY `rank`, avg_score DESC LIMIT 10''').execute()
for restaurant in result.fetch_all():
print "%s - %s - %d " % (restaurant[0], restaurant[1], restaurant[2])
session.close()
Copyright @ 2019 Oracle and/or its affiliates.
63 / 111
Output
Copyright @ 2019 Oracle and/or its affiliates.
64 / 111
And back to JSON
And of course it's possible to return the result as a JSON document:
result = session.sql('''select JSON_PRETTY(JSON_ARRAYAGG(JSON_OBJECT(
"name", name, "cuisine", cuisine,
"score", avg_score)))
from (WITH cte1 AS (SELECT doc->>"$.name" AS name,
doc->>"$.cuisine" AS cuisine,
(SELECT AVG(score)
FROM JSON_TABLE(doc, "$.grades[*]"
COLUMNS (score INT PATH "$.score"))
AS r) AS avg_score
FROM docstore.all_recs) SELECT *, RANK() OVER
(PARTITION BY cuisine ORDER BY avg_score DESC)
AS `rank`
FROM cte1 ORDER BY `rank`, avg_score
DESC LIMIT 10) as t''').execute()
row = result.fetch_one()
print row[0]
Copyright @ 2019 Oracle and/or its affiliates.
65 / 111
 
And back to JSON - output
Copyright @ 2019 Oracle and/or its affiliates.
66 / 111
some extras...
The hidden part of the iceberg
Copyright @ 2019 Oracle and/or its affiliates.
67 / 111
_id Every document has a unique identi er called the document ID. It can
be manually assigned when adding a document or generated and
assigned to the document automatically !
Since MySQL 8.0.11, the _id is generated by the server. To get the list
of automatically generated IDs use the result.getGeneratedIDs()
method.
The _id is made of 3 parts, all hex encoded:
pre x
timestamp when the MySQL Server instance was started
auto-increment counter
Globally unique IDs
Optimized for InnoDB storage
Examples
00005cc17b700000000000000003
Copyright @ 2019 Oracle and/or its affiliates.
68 / 111
Document Store Full ACID !
It relies on the proven MySQL InnoDB's strength & robustness:
Copyright @ 2019 Oracle and/or its affiliates.
69 / 111
Document Store Full ACID !
It relies on the proven MySQL InnoDB's strength & robustness:
innodb_ ush_log_at_trx_commit = 1
Copyright @ 2019 Oracle and/or its affiliates.
70 / 111
Document Store Full ACID !
It relies on the proven MySQL InnoDB's strength & robustness:
innodb_ ush_log_at_trx_commit = 1
innodb_doublewrite = ON
Copyright @ 2019 Oracle and/or its affiliates.
71 / 111
Document Store Full ACID !
It relies on the proven MySQL InnoDB's strength & robustness:
innodb_ ush_log_at_trx_commit = 1
innodb_doublewrite = ON
sync_binlog = 1
Copyright @ 2019 Oracle and/or its affiliates.
72 / 111
Document Store Full ACID !
It relies on the proven MySQL InnoDB's strength & robustness:
innodb_ ush_log_at_trx_commit = 1
innodb_doublewrite = ON
sync_binlog = 1
transaction_isolation = REPEATABLE-READ|READ-COMMITTED|...
Copyright @ 2019 Oracle and/or its affiliates.
73 / 111
Document Store Full ACID !
It relies on the proven MySQL InnoDB's strength & robustness:
innodb_ ush_log_at_trx_commit = 1
innodb_doublewrite = ON
sync_binlog = 1
transaction_isolation = REPEATABLE-READ|READ-COMMITTED|...
We do care about your data !
Copyright @ 2019 Oracle and/or its affiliates.
74 / 111
What time is it now ?
Time for some more
examples !
Copyright @ 2019 Oracle and/or its affiliates.
75 / 111
More fun with The Walking Dead
Copyright @ 2019 Oracle and/or its affiliates.
76 / 111
Example: All Episodes of Season 1
Copyright @ 2019 Oracle and/or its affiliates.
77 / 111
Example: All First Episodes of Each Season
Copyright @ 2019 Oracle and/or its affiliates.
78 / 111
Example: Speed Up Episode's Name Lookup
Copyright @ 2019 Oracle and/or its affiliates.
79 / 111
Example: Speed Up Episode's Name Lookup
Copyright @ 2019 Oracle and/or its affiliates.
80 / 111
Example: Speed Up Episode's Name Lookup
Copyright @ 2019 Oracle and/or its affiliates.
81 / 111
Example: Transaction
Copyright @ 2019 Oracle and/or its affiliates.
82 / 111
Example: Do more with SQL
List the amount of episodes by season:
Copyright @ 2019 Oracle and/or its affiliates.
83 / 111
Example: Do more with SQL (2)
Episode statistics for each season:
Copyright @ 2019 Oracle and/or its affiliates.
84 / 111
Example: Do more with SQL (3)
Number of days between episodes:
Copyright @ 2019 Oracle and/or its affiliates.
85 / 111
JSON Data validation
It's possible to have constraints between collections (or tables):
Copyright @ 2019 Oracle and/or its affiliates.
86 / 111
JSON Data validation (2)
Let's see in SQL how the 2 collections look like:
Copyright @ 2019 Oracle and/or its affiliates.
87 / 111
JSON Data validation (3)
Let's add one virtual column in each collection:
Copyright @ 2019 Oracle and/or its affiliates.
88 / 111
JSON Data validation (4)
Now we can index the reference and create the constraint:
Copyright @ 2019 Oracle and/or its affiliates.
89 / 111
JSON Data validation (4)
Copyright @ 2019 Oracle and/or its affiliates.
90 / 111
JSON Data validation (5)
And now even in pure NoSQL CRUD, we can see the data validation in action:
Copyright @ 2019 Oracle and/or its affiliates.
91 / 111
JSON Schema validation - NEW 8.0.16
Since MySQL 8.0.16, CHECK constraints are now supported !
Copyright @ 2019 Oracle and/or its affiliates.
92 / 111
JSON Schema validation - NEW 8.0.16
Since MySQL 8.0.16, CHECK constraints are now supported !
Copyright @ 2019 Oracle and/or its affiliates.
93 / 111
JSON Schema validation - NEW 8.0.16
Since MySQL 8.0.16, CHECK constraints are now supported !
Copyright @ 2019 Oracle and/or its affiliates.
94 / 111
JSON Schema validation (2) - NEW 8.0.17
New JSON_SCHEMA_VALID function:
Copyright @ 2019 Oracle and/or its affiliates.
95 / 111
JSON Schema validation (2) - NEW 8.0.17
New JSON_SCHEMA_VALID function:
Copyright @ 2019 Oracle and/or its affiliates.
96 / 111
JSON Schema validation (3) - NEW 8.0.17
Knowing why thanks to the new JSON_SCHEMA_VALIDATION_REPORT function:
Copyright @ 2019 Oracle and/or its affiliates.
97 / 111
JSON Schema validation (4) - NEW 8.0.17
And nally, mixing JSON_SCHEMA_VALID with CHECK CONSTRAINT:
Copyright @ 2019 Oracle and/or its affiliates.
98 / 111
JSON Schema validation (4) - NEW 8.0.17
And nally, mixing JSON_SCHEMA_VALID with CHECK CONSTRAINT:
Copyright @ 2019 Oracle and/or its affiliates.
99 / 111
what do I gain ?
Conclusion
Copyright @ 2019 Oracle and/or its affiliates.
100 / 111
schemaless
exible data structure
easy to start (CRUD)
Conclusion
This is the best of the two worlds in one product !
Data integrity
ACID Compliant
Transactions
SQL
Copyright @ 2019 Oracle and/or its affiliates.
101 / 111
8.0
http://lefred.be/content/top-10-reasons-for-
nosql-with-mysql/
Copyright @ 2019 Oracle and/or its affiliates.
102 / 111
8.0
h ps://www.slideshare.net/lefred.descamps/mysql-
shell-the-best-dba-tool
h ps://github.com/lefred/mysql-shell-
mydba
h ps://github.com/lefred/mysql-shell-
innotop
More with MySQL Shell & Python
Copyright @ 2019 Oracle and/or its affiliates.
103 / 111
MySQL Shell Reporting Framework - 8.0.16
Now it's also possible to create user-de ned reports directly in the Shell. They can be
wri en in Python and called the same way on every operating systems. No need for extra
libraries !
More Info:
h ps://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-reporting.html
h ps://mysql.wisborg.dk/2019/04/26/mysql-shell-8-0-16-built-in-reports/
h ps://mysql.wisborg.dk/2019/04/27/mysql-shell-8-0-16-user-de ned-reports/
Copyright @ 2019 Oracle and/or its affiliates.
104 / 111
MySQL Shell Extentions & Plugins - 8.0.17
Since 8.0.17, MySQL Shell has been extended to allow you to write your own extensions
and plugins !
More Info:
h ps://mysqlserverteam.com/mysql-shell-plugins-introduction/
h ps://lefred.be/content/overview-on-mysql-shell-8-0-17-extensions-plugins-and-
how-to-write-yours/
Copyright @ 2019 Oracle and/or its affiliates.
105 / 111
Credits
Thank you Olivier Dasini for some TV Show examples:
h p://dasini.net/blog/2019/04/02/mysql-json-document-store/
Thank you Jesper Wisborg Krogh for inspiration extending the MySQL Shell
Copyright @ 2019 Oracle and/or its affiliates.
106 / 111
107 / 111
Thank you !
Copyright @ 2019 Oracle and/or its affiliates.
108 / 111
109 / 111
Upgrade to MySQL 8.0
It's time to upgrade to MySQL 8.0, the
fastest MySQL adoption release ever !
Copyright @ 2019 Oracle and/or its affiliates.
110 / 111
Session Survey
Help us make the content even be er.
Please complete the session survey in
the Mobile App.
Copyright @ 2019 Oracle and/or its affiliates.
111 / 111

More Related Content

What's hot (20)

PDF
MySQL InnoDB Cluster - Advanced Configuration & Operations
Frederic Descamps
 
PDF
Looking Inside the MySQL 8.0 Document Store
Frederic Descamps
 
PDF
MySQL Shell - the best DBA tool !
Frederic Descamps
 
PDF
Another MySQL HA Solution for ProxySQL Users, Easy and All Integrated: MySQL ...
Frederic Descamps
 
PDF
UAE MySQL Users Group Meet-up : MySQL Shell Document Store & more...
Frederic Descamps
 
PDF
MySQL Database Service Webinar - Installing WordPress in OCI with MDS
Frederic Descamps
 
PDF
MySQL Group Replication: Handling Network Glitches - Best Practices
Frederic Descamps
 
PDF
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
Frederic Descamps
 
PDF
MySQL Tech Café #8: MySQL 8.0 for Python Developers
Frederic Descamps
 
PDF
MySQL : State of the Dolphin May 2019
Frederic Descamps
 
PDF
MySQL Day Virtual: Best Practices Tips - Upgrading to MySQL 8.0
Frederic Descamps
 
PDF
DataOpsbarcelona 2019: Deep dive into MySQL Group Replication... the magic e...
Frederic Descamps
 
PDF
Hash join in MySQL 8
Erik Frøseth
 
PDF
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
Frederic Descamps
 
PDF
the State of the Dolphin - October 2020
Frederic Descamps
 
PDF
Cloud native - Why to use MySQL 8.0 and how to use it on oci with MDS
Frederic Descamps
 
PDF
MySQL InnoDB Cluster and Group Replication in a Nutshell: hands-on tutorial
Frederic Descamps
 
PDF
Oracle Open World 2018 / Code One : MySQL 8.0 Document Store
Frederic Descamps
 
PDF
Percona Live Europe 2018 MySQL Group Replication... the magic explained
Frederic Descamps
 
PDF
MySQL InnoDB Cluster and Group Replication in a Nutshell
Frederic Descamps
 
MySQL InnoDB Cluster - Advanced Configuration & Operations
Frederic Descamps
 
Looking Inside the MySQL 8.0 Document Store
Frederic Descamps
 
MySQL Shell - the best DBA tool !
Frederic Descamps
 
Another MySQL HA Solution for ProxySQL Users, Easy and All Integrated: MySQL ...
Frederic Descamps
 
UAE MySQL Users Group Meet-up : MySQL Shell Document Store & more...
Frederic Descamps
 
MySQL Database Service Webinar - Installing WordPress in OCI with MDS
Frederic Descamps
 
MySQL Group Replication: Handling Network Glitches - Best Practices
Frederic Descamps
 
preFOSDEM MySQL Day - Best Practices to Upgrade to MySQL 8.0
Frederic Descamps
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
Frederic Descamps
 
MySQL : State of the Dolphin May 2019
Frederic Descamps
 
MySQL Day Virtual: Best Practices Tips - Upgrading to MySQL 8.0
Frederic Descamps
 
DataOpsbarcelona 2019: Deep dive into MySQL Group Replication... the magic e...
Frederic Descamps
 
Hash join in MySQL 8
Erik Frøseth
 
MySQL InnoDB Cluster and Group Replication in a nutshell hands-on tutorial
Frederic Descamps
 
the State of the Dolphin - October 2020
Frederic Descamps
 
Cloud native - Why to use MySQL 8.0 and how to use it on oci with MDS
Frederic Descamps
 
MySQL InnoDB Cluster and Group Replication in a Nutshell: hands-on tutorial
Frederic Descamps
 
Oracle Open World 2018 / Code One : MySQL 8.0 Document Store
Frederic Descamps
 
Percona Live Europe 2018 MySQL Group Replication... the magic explained
Frederic Descamps
 
MySQL InnoDB Cluster and Group Replication in a Nutshell
Frederic Descamps
 

Similar to Python and MySQL 8.0 Document Store (20)

PDF
PyConX - Python & MySQL 8.0 Document Store
Frederic Descamps
 
PDF
MySQL 8.0 Introduction to NoSQL + SQL
Manuel Contreras
 
PDF
MySQL Day Paris 2018 - What’s New in MySQL 8.0 ?
Olivier DASINI
 
PDF
20171104 hk-py con-mysql-documentstore_v1
Ivan Ma
 
PDF
MySQL 8.0 - What's New ?
Olivier DASINI
 
PDF
MySQL 8.0, what's new ? - Forum PHP 2018
Olivier DASINI
 
PDF
MySQL Document Store for Modern Applications
Olivier DASINI
 
PDF
MySQL Document Store and Node.JS
Reggie Burnett
 
PPTX
A Step by Step Introduction to the MySQL Document Store
Dave Stokes
 
PDF
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
Ryusuke Kajiyama
 
PDF
MySQL Day Paris 2018 - MySQL JSON Document Store
Olivier DASINI
 
PDF
Node.js and the MySQL Document Store
Rui Quelhas
 
PDF
MySQL Document Store - A Document Store with all the benefts of a Transactona...
Olivier DASINI
 
PDF
Python and the MySQL Document Store
Jesper Wisborg Krogh
 
PDF
MySQL Document Store (Oracle Code Warsaw 2018)
Vittorio Cioe
 
PDF
MySQL 8 loves JavaScript
Sanjay Manwani
 
PDF
MySQL Document Store -- SCaLE 17x Presentation
Dave Stokes
 
PDF
MySQL Document Store
Mario Beck
 
PDF
20190713_MySQL開発最新動向
Machiko Ikoma
 
PDF
MySQL Day Paris 2016 - MySQL as a Document Store
Olivier DASINI
 
PyConX - Python & MySQL 8.0 Document Store
Frederic Descamps
 
MySQL 8.0 Introduction to NoSQL + SQL
Manuel Contreras
 
MySQL Day Paris 2018 - What’s New in MySQL 8.0 ?
Olivier DASINI
 
20171104 hk-py con-mysql-documentstore_v1
Ivan Ma
 
MySQL 8.0 - What's New ?
Olivier DASINI
 
MySQL 8.0, what's new ? - Forum PHP 2018
Olivier DASINI
 
MySQL Document Store for Modern Applications
Olivier DASINI
 
MySQL Document Store and Node.JS
Reggie Burnett
 
A Step by Step Introduction to the MySQL Document Store
Dave Stokes
 
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
Ryusuke Kajiyama
 
MySQL Day Paris 2018 - MySQL JSON Document Store
Olivier DASINI
 
Node.js and the MySQL Document Store
Rui Quelhas
 
MySQL Document Store - A Document Store with all the benefts of a Transactona...
Olivier DASINI
 
Python and the MySQL Document Store
Jesper Wisborg Krogh
 
MySQL Document Store (Oracle Code Warsaw 2018)
Vittorio Cioe
 
MySQL 8 loves JavaScript
Sanjay Manwani
 
MySQL Document Store -- SCaLE 17x Presentation
Dave Stokes
 
MySQL Document Store
Mario Beck
 
20190713_MySQL開発最新動向
Machiko Ikoma
 
MySQL Day Paris 2016 - MySQL as a Document Store
Olivier DASINI
 
Ad

More from Frederic Descamps (20)

PDF
MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
Frederic Descamps
 
PDF
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
Frederic Descamps
 
PDF
RivieraJUG - MySQL Indexes and Histograms
Frederic Descamps
 
PDF
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
Frederic Descamps
 
PDF
MySQL User Group NL - MySQL 8
Frederic Descamps
 
PDF
State of the Dolphin - May 2022
Frederic Descamps
 
PDF
Percona Live 2022 - MySQL Shell for Visual Studio Code
Frederic Descamps
 
PDF
Percona Live 2022 - The Evolution of a MySQL Database System
Frederic Descamps
 
PDF
Percona Live 2022 - MySQL Architectures
Frederic Descamps
 
PDF
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
Frederic Descamps
 
PDF
Open Source 101 2022 - MySQL Indexes and Histograms
Frederic Descamps
 
PDF
Pi Day 2022 - from IoT to MySQL HeatWave Database Service
Frederic Descamps
 
PDF
Confoo 2022 - le cycle d'une instance MySQL
Frederic Descamps
 
PDF
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
Frederic Descamps
 
PDF
Les nouveautés de MySQL 8.0
Frederic Descamps
 
PDF
Les nouveautés de MySQL 8.0
Frederic Descamps
 
PDF
State of The Dolphin - May 2021
Frederic Descamps
 
PDF
MySQL Shell for DBAs
Frederic Descamps
 
PDF
Deploying Magento on OCI with MDS
Frederic Descamps
 
PDF
MySQL Router REST API
Frederic Descamps
 
MySQL Innovation & Cloud Day - Document Store avec MySQL HeatWave Database Se...
Frederic Descamps
 
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
Frederic Descamps
 
RivieraJUG - MySQL Indexes and Histograms
Frederic Descamps
 
RivieraJUG - MySQL 8.0 - What's new for developers.pdf
Frederic Descamps
 
MySQL User Group NL - MySQL 8
Frederic Descamps
 
State of the Dolphin - May 2022
Frederic Descamps
 
Percona Live 2022 - MySQL Shell for Visual Studio Code
Frederic Descamps
 
Percona Live 2022 - The Evolution of a MySQL Database System
Frederic Descamps
 
Percona Live 2022 - MySQL Architectures
Frederic Descamps
 
LinuxFest Northwest 2022 - The Evolution of a MySQL Database System
Frederic Descamps
 
Open Source 101 2022 - MySQL Indexes and Histograms
Frederic Descamps
 
Pi Day 2022 - from IoT to MySQL HeatWave Database Service
Frederic Descamps
 
Confoo 2022 - le cycle d'une instance MySQL
Frederic Descamps
 
FOSDEM 2022 MySQL Devroom: MySQL 8.0 - Logical Backups, Snapshots and Point-...
Frederic Descamps
 
Les nouveautés de MySQL 8.0
Frederic Descamps
 
Les nouveautés de MySQL 8.0
Frederic Descamps
 
State of The Dolphin - May 2021
Frederic Descamps
 
MySQL Shell for DBAs
Frederic Descamps
 
Deploying Magento on OCI with MDS
Frederic Descamps
 
MySQL Router REST API
Frederic Descamps
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 

Python and MySQL 8.0 Document Store

  • 2. Python and MySQL 8.0 Document Store DEV5966 Frédéric Descamps Community Manager MySQL September 2019 2 / 111
  • 3.   Safe Harbor The following is intended to outline our general product direction. It is intended for information purpose only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied up in making purchasing decisions. The development, release, timing and pricing of any features or functionality described for Oracle's product may change and remains at the sole discretion of Oracle Corporation. Statement in this presentation relating to Oracle's future plans, expectations, beliefs, intentions and ptospects are "forward-looking statements" and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that a ect our business is contained in Oracle's Securities and Exchange Commission (SEC) lings, including our most recent reports on Form 10-K and Form 10-Q under the heading "Risk Factors". These lings are available on the SEC's website or on Oracle's website at h p://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Copyright @ 2019 Oracle and/or its affiliates. 3 / 111
  • 4. about.me/lefred Who am I ? Copyright @ 2019 Oracle and/or its affiliates. 4 / 111
  • 5. Frédéric Descamps @lefred MySQL Evangelist Managing MySQL since 3.23 devops believer living in Belgium 🇧🇪 h ps://lefred.be Copyright @ 2019 Oracle and/or its affiliates. 5 / 111
  • 6. MySQL and JSON How MySQL works with JSON Copyright @ 2019 Oracle and/or its affiliates. 6 / 111
  • 7. JavaScript Object Notation (JSON) { "_id": "5ad5b645f88c5bb8fe3fd337", "name": "Morris Park Bake Shop", "grades": [ { "date": "2014-03-03T00:00:00Z", "grade": "A", "score": 2 }, ], "address": { "coord": [ -73.856077, 40.848447 ], "street": "Morris Park Ave", "zipcode": "10462", "building": "1007" }, "borough": "Bronx", "cuisine": "Bakery", "restaurant_id": "30075445" } Copyright @ 2019 Oracle and/or its affiliates. 7 / 111
  • 8. 8.0 MySQL has Native JSON Support JSON data type since MySQL 5.7 Copyright @ 2019 Oracle and/or its affiliates. 8 / 111
  • 9. 8.0 MySQL has Native JSON Support JSON data type since MySQL 5.7 Stored as binary object Copyright @ 2019 Oracle and/or its affiliates. 9 / 111
  • 10. 8.0 MySQL has Native JSON Support JSON data type since MySQL 5.7 Stored as binary object Support for partial updates in MySQL 8.0 Copyright @ 2019 Oracle and/or its affiliates. 10 / 111
  • 11. 8.0 MySQL has Native JSON Support JSON data type since MySQL 5.7 Stored as binary object Support for partial updates in MySQL 8.0 30 JSON functions Copyright @ 2019 Oracle and/or its affiliates. 11 / 111
  • 12. 8.0 ... and support JSON Paths $.address.coord[*] $ the root of the document Copyright @ 2019 Oracle and/or its affiliates. 12 / 111
  • 13. 8.0 ... and support JSON Paths $.address.coord[*] $ the root of the document . path leg separator Copyright @ 2019 Oracle and/or its affiliates. 13 / 111
  • 14. 8.0 ... and support JSON Paths $.address.coord[*] $ the root of the document . path leg separator * wildcard: Copyright @ 2019 Oracle and/or its affiliates. 14 / 111
  • 15. 8.0 ... and support JSON Paths $.address.coord[*] $ the root of the document . path leg separator * wildcard: .* all members in the object [*] all values in the array [pre x]**su x path beginning with pre x and ending with su x Copyright @ 2019 Oracle and/or its affiliates. 15 / 111
  • 16. MySQL Document Store the Solution Copyright @ 2019 Oracle and/or its affiliates. 16 / 111
  • 17. Built on the MySQL JSON Data type and Proven MySQL Server Technology Provides a schema exible JSON Document Store No SQL required No need to de ne all possible a ributes, tables, etc. Uses new X DevAPI Can leverage generated column to extract JSON values into materialized columns that can be indexed for fast SQL searches. Document can be ~1GB It's a column in a row of a table It cannot exceed max_allowed_packet Allows use of modern programming styles No more embedded strings of SQL in your code Easy to read Also works with relational Tables Proven MySQL Technology Copyright @ 2019 Oracle and/or its affiliates. 17 / 111
  • 18. X Protocol Connectors Copyright @ 2019 Oracle and/or its affiliates. 18 / 111
  • 19. X DevAPI Developed from scratch for modern development Supports: SQL NoSQL - JSON documents NoSQL - SQL tables Uniform API across programming languages We provide connectors for C++, Java, .Net, Node.js, Python, PHP working with Communities to help them supporting it too Supported in the MySQL Shell Full ACID support Savepoints Connection pools (as of 8.0.13) Copyright @ 2019 Oracle and/or its affiliates. 19 / 111
  • 20. PY JS SQL > MySQL 8.0 Upgrade Checker Auto Completion & Command History Output Formats (table, json, tabs) Prompt Themes Batch Execution 5.7 8.0 JS Document Store X dev API SQL CLI InnoDB Cluster importJSON JSJS parallel importTABLE data Copyright @ 2019 Oracle and/or its affiliates. 20 / 111
  • 21. Migration from MongoDB to MySQL DS For this example, I will use the well known restaurants collection: Copyright @ 2019 Oracle and/or its affiliates. 21 / 111
  • 22. Migration from MongoDB to MySQL DS For this example, I will use the well known restaurants collection: Copyright @ 2019 Oracle and/or its affiliates. 22 / 111
  • 23. Copyright @ 2019 Oracle and/or its affiliates. 23 / 111
  • 24. Copyright @ 2019 Oracle and/or its affiliates. 24 / 111
  • 25. Let's query Copyright @ 2019 Oracle and/or its affiliates. 25 / 111
  • 26. Let's query That's too much records to show on this slide... Copyright @ 2019 Oracle and/or its affiliates. 26 / 111
  • 27. Let's query That's too much records to show on this slide... Copyright @ 2019 Oracle and/or its affiliates. 27 / 111
  • 28. Let's query That's too much records to show on this slide... Let's add a limit to it Copyright @ 2019 Oracle and/or its affiliates. 28 / 111
  • 29.   Copyright @ 2019 Oracle and/or its affiliates. 29 / 111
  • 30. Some more examples Copyright @ 2019 Oracle and/or its affiliates. 30 / 111
  • 31. Some more examples Let's add a selection criteria: Copyright @ 2019 Oracle and/or its affiliates. 31 / 111
  • 32. Using IN... Copyright @ 2019 Oracle and/or its affiliates. 32 / 111
  • 33. Syntax slightly different than MongoDB Copyright @ 2019 Oracle and/or its affiliates. 33 / 111
  • 34. Syntax slightly different than MongoDB Copyright @ 2019 Oracle and/or its affiliates. 34 / 111
  • 35. CRUD operations Copyright @ 2019 Oracle and/or its affiliates. 35 / 111
  • 36. CRUD operations for collections Add a document Copyright @ 2019 Oracle and/or its affiliates. 36 / 111
  • 37. CRUD operations for collections Add a document collection.add({ name: 'fred', age: 42 }) .add({ name: 'dave', age: 23 }) .execute() collection.add([ { name: 'dimo', age: 50 }, { name: 'kenny', age: 25 } ]).execute() Copyright @ 2019 Oracle and/or its affiliates. 37 / 111
  • 38. CRUD operations for collections Modify a document Copyright @ 2019 Oracle and/or its affiliates. 38 / 111
  • 39. CRUD operations for collections Modify a document collection.modify('name = :name') .bind('name', 'fred') .set('age', 43) .sort('name ASC') .limit(1) .execute() collection.modify('name = :name') .bind('name', 'fred') .patch({ age: 43, active: false }) .sort('name DESC') .limit(1) .execute() Copyright @ 2019 Oracle and/or its affiliates. 39 / 111
  • 40. CRUD operations for collections Remove a document Copyright @ 2019 Oracle and/or its affiliates. 40 / 111
  • 41. CRUD operations for collections Remove a document collection.remove('name = :name') .bind('name', 'fred') .sort('age ASC') .limit(1) .execute() Copyright @ 2019 Oracle and/or its affiliates. 41 / 111
  • 42. MySQL Document Store Objects Summary Copyright @ 2019 Oracle and/or its affiliates. 42 / 111
  • 43. All you need to know is here: h ps://dev.mysql.com/doc/x-devapi-userguide/en/crud-operations-overview.html Copyright @ 2019 Oracle and/or its affiliates. 43 / 111
  • 44. MySQL Connector Python The Python connector for MySQL Copyright @ 2019 Oracle and/or its affiliates. 44 / 111
  • 45. NoSQL SQL   MySQL Connector/Python 8 GA since April 2018 Copyright @ 2019 Oracle and/or its affiliates. 45 / 111
  • 46. NoSQL SQL   MySQL Connector/Python 8 GA since April 2018 Maintained by Oracle Copyright @ 2019 Oracle and/or its affiliates. 46 / 111
  • 47. NoSQL SQL   MySQL Connector/Python 8 GA since April 2018 Maintained by Oracle Dual license Copyright @ 2019 Oracle and/or its affiliates. 47 / 111
  • 48. NoSQL SQL   MySQL Connector/Python 8 GA since April 2018 Maintained by Oracle Dual license Support MySQL Server 5.5, 5.6, 5.7 and 8.0 Copyright @ 2019 Oracle and/or its affiliates. 48 / 111
  • 49. NoSQL SQL   MySQL Connector/Python 8 GA since April 2018 Maintained by Oracle Dual license Support MySQL Server 5.5, 5.6, 5.7 and 8.0 SQL and NoSQL support Copyright @ 2019 Oracle and/or its affiliates. 49 / 111
  • 50. NoSQL SQL   MySQL Connector/Python 8 GA since April 2018 Maintained by Oracle Dual license Support MySQL Server 5.5, 5.6, 5.7 and 8.0 SQL and NoSQL support Table and JSON Document support Copyright @ 2019 Oracle and/or its affiliates. 50 / 111
  • 51. MySQL Connector/Python 8 - 3 APIs Choice of Three APIs API Python Module Comment PEP249 Python Database API mysql.connector The traditional API C Extension API _mysql_connector Similar to the MySQL C API MySQL X DevAPI mysqlx New in 8.0, both SQL and NoSQL   All you need to know is here: h ps://dev.mysql.com/doc/connector-python/en/ Copyright @ 2019 Oracle and/or its affiliates. 51 / 111
  • 52.  DATABASES = { 'default': { 'NAME': 'user_data', 'ENGINE': 'mysql.connector.django', 'USER': 'mysql_user', 'PASSWORD': 'password', 'OPTIONS': { 'autocommit': True, }, } } MySQL Connect/Python and Django MySQL Connector/Python includes also a mysql.connector.django module that provides a Django back end for MySQL Copyright @ 2019 Oracle and/or its affiliates. 52 / 111
  • 53. MySQL Connector/Python 8 - installation easiest, use pip: use a MySQL repository for your distribution (fedora, ubuntu, debian, ...) Copyright @ 2019 Oracle and/or its affiliates. 53 / 111
  • 54. MySQL Connector/Python 8 - installation or go to h ps://dev.mysql.com/downloads/connector/python/ Copyright @ 2019 Oracle and/or its affiliates. 54 / 111
  • 55. What time is it ? Time to code ! Copyright @ 2019 Oracle and/or its affiliates. 55 / 111
  • 56. Some coding... import mysqlx session = mysqlx.get_session( { 'host': 'localhost', 'port': 33060, 'user': 'fred', 'password': 'fred' }) db = session.get_schema('docstore') col = db.get_collection('all_recs') restaurants = col. nd("cuisine='Italian'"). elds("name, cuisine, borough") .limit(3).execute() for restaurant in restaurants.fetch_all(): print restaurant session.close() Copyright @ 2019 Oracle and/or its affiliates. 56 / 111
  • 57. If it was not yet obvious, you can now use MySQL without SQL ! Copyright @ 2019 Oracle and/or its affiliates. 57 / 111
  • 58. OK we have Document Store, CRUD and ACID but what makes MySQL Document Store unique ? Copyright @ 2019 Oracle and/or its affiliates. 58 / 111
  • 59. Challenge: list the best restaurant of each type of food and show the top 10, with the best one first !   don't forget that all these restaurants are just JSON documents Copyright @ 2019 Oracle and/or its affiliates. 59 / 111
  • 60. NoSQL as SQL - aggregation Copyright @ 2019 Oracle and/or its affiliates. 60 / 111
  • 61. NoSQL as SQL - aggregation Copyright @ 2019 Oracle and/or its affiliates. 61 / 111
  • 62. NoSQL as SQL - aggregation Copyright @ 2019 Oracle and/or its affiliates. 62 / 111
  • 63. import mysqlx session = mysqlx.get_session( { 'host': 'localhost', 'port': 33060, 'user': 'fred', 'password': 'fred' }) db = session.get_schema('docstore') col = db.get_collection('all_recs') restaurants = col. nd("cuisine='Italian'"). elds("name, cuisine, borough") .limit(3).execute() for restaurant in restaurants.fetch_all(): print restaurant result = session.sql('''WITH cte1 AS (SELECT doc->>"$.name" AS name, doc->>"$.cuisine" AS cuisine, (SELECT AVG(score) FROM JSON_TABLE(doc, "$.grades[*]" COLUMNS (score INT PATH "$.score")) AS r) AS avg_score FROM docstore.all_recs) SELECT *, RANK() OVER (PARTITION BY cuisine ORDER BY avg_score DESC) AS `rank` FROM cte1 ORDER BY `rank`, avg_score DESC LIMIT 10''').execute() for restaurant in result.fetch_all(): print "%s - %s - %d " % (restaurant[0], restaurant[1], restaurant[2]) session.close() Copyright @ 2019 Oracle and/or its affiliates. 63 / 111
  • 64. Output Copyright @ 2019 Oracle and/or its affiliates. 64 / 111
  • 65. And back to JSON And of course it's possible to return the result as a JSON document: result = session.sql('''select JSON_PRETTY(JSON_ARRAYAGG(JSON_OBJECT( "name", name, "cuisine", cuisine, "score", avg_score))) from (WITH cte1 AS (SELECT doc->>"$.name" AS name, doc->>"$.cuisine" AS cuisine, (SELECT AVG(score) FROM JSON_TABLE(doc, "$.grades[*]" COLUMNS (score INT PATH "$.score")) AS r) AS avg_score FROM docstore.all_recs) SELECT *, RANK() OVER (PARTITION BY cuisine ORDER BY avg_score DESC) AS `rank` FROM cte1 ORDER BY `rank`, avg_score DESC LIMIT 10) as t''').execute() row = result.fetch_one() print row[0] Copyright @ 2019 Oracle and/or its affiliates. 65 / 111
  • 66.   And back to JSON - output Copyright @ 2019 Oracle and/or its affiliates. 66 / 111
  • 67. some extras... The hidden part of the iceberg Copyright @ 2019 Oracle and/or its affiliates. 67 / 111
  • 68. _id Every document has a unique identi er called the document ID. It can be manually assigned when adding a document or generated and assigned to the document automatically ! Since MySQL 8.0.11, the _id is generated by the server. To get the list of automatically generated IDs use the result.getGeneratedIDs() method. The _id is made of 3 parts, all hex encoded: pre x timestamp when the MySQL Server instance was started auto-increment counter Globally unique IDs Optimized for InnoDB storage Examples 00005cc17b700000000000000003 Copyright @ 2019 Oracle and/or its affiliates. 68 / 111
  • 69. Document Store Full ACID ! It relies on the proven MySQL InnoDB's strength & robustness: Copyright @ 2019 Oracle and/or its affiliates. 69 / 111
  • 70. Document Store Full ACID ! It relies on the proven MySQL InnoDB's strength & robustness: innodb_ ush_log_at_trx_commit = 1 Copyright @ 2019 Oracle and/or its affiliates. 70 / 111
  • 71. Document Store Full ACID ! It relies on the proven MySQL InnoDB's strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON Copyright @ 2019 Oracle and/or its affiliates. 71 / 111
  • 72. Document Store Full ACID ! It relies on the proven MySQL InnoDB's strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON sync_binlog = 1 Copyright @ 2019 Oracle and/or its affiliates. 72 / 111
  • 73. Document Store Full ACID ! It relies on the proven MySQL InnoDB's strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON sync_binlog = 1 transaction_isolation = REPEATABLE-READ|READ-COMMITTED|... Copyright @ 2019 Oracle and/or its affiliates. 73 / 111
  • 74. Document Store Full ACID ! It relies on the proven MySQL InnoDB's strength & robustness: innodb_ ush_log_at_trx_commit = 1 innodb_doublewrite = ON sync_binlog = 1 transaction_isolation = REPEATABLE-READ|READ-COMMITTED|... We do care about your data ! Copyright @ 2019 Oracle and/or its affiliates. 74 / 111
  • 75. What time is it now ? Time for some more examples ! Copyright @ 2019 Oracle and/or its affiliates. 75 / 111
  • 76. More fun with The Walking Dead Copyright @ 2019 Oracle and/or its affiliates. 76 / 111
  • 77. Example: All Episodes of Season 1 Copyright @ 2019 Oracle and/or its affiliates. 77 / 111
  • 78. Example: All First Episodes of Each Season Copyright @ 2019 Oracle and/or its affiliates. 78 / 111
  • 79. Example: Speed Up Episode's Name Lookup Copyright @ 2019 Oracle and/or its affiliates. 79 / 111
  • 80. Example: Speed Up Episode's Name Lookup Copyright @ 2019 Oracle and/or its affiliates. 80 / 111
  • 81. Example: Speed Up Episode's Name Lookup Copyright @ 2019 Oracle and/or its affiliates. 81 / 111
  • 82. Example: Transaction Copyright @ 2019 Oracle and/or its affiliates. 82 / 111
  • 83. Example: Do more with SQL List the amount of episodes by season: Copyright @ 2019 Oracle and/or its affiliates. 83 / 111
  • 84. Example: Do more with SQL (2) Episode statistics for each season: Copyright @ 2019 Oracle and/or its affiliates. 84 / 111
  • 85. Example: Do more with SQL (3) Number of days between episodes: Copyright @ 2019 Oracle and/or its affiliates. 85 / 111
  • 86. JSON Data validation It's possible to have constraints between collections (or tables): Copyright @ 2019 Oracle and/or its affiliates. 86 / 111
  • 87. JSON Data validation (2) Let's see in SQL how the 2 collections look like: Copyright @ 2019 Oracle and/or its affiliates. 87 / 111
  • 88. JSON Data validation (3) Let's add one virtual column in each collection: Copyright @ 2019 Oracle and/or its affiliates. 88 / 111
  • 89. JSON Data validation (4) Now we can index the reference and create the constraint: Copyright @ 2019 Oracle and/or its affiliates. 89 / 111
  • 90. JSON Data validation (4) Copyright @ 2019 Oracle and/or its affiliates. 90 / 111
  • 91. JSON Data validation (5) And now even in pure NoSQL CRUD, we can see the data validation in action: Copyright @ 2019 Oracle and/or its affiliates. 91 / 111
  • 92. JSON Schema validation - NEW 8.0.16 Since MySQL 8.0.16, CHECK constraints are now supported ! Copyright @ 2019 Oracle and/or its affiliates. 92 / 111
  • 93. JSON Schema validation - NEW 8.0.16 Since MySQL 8.0.16, CHECK constraints are now supported ! Copyright @ 2019 Oracle and/or its affiliates. 93 / 111
  • 94. JSON Schema validation - NEW 8.0.16 Since MySQL 8.0.16, CHECK constraints are now supported ! Copyright @ 2019 Oracle and/or its affiliates. 94 / 111
  • 95. JSON Schema validation (2) - NEW 8.0.17 New JSON_SCHEMA_VALID function: Copyright @ 2019 Oracle and/or its affiliates. 95 / 111
  • 96. JSON Schema validation (2) - NEW 8.0.17 New JSON_SCHEMA_VALID function: Copyright @ 2019 Oracle and/or its affiliates. 96 / 111
  • 97. JSON Schema validation (3) - NEW 8.0.17 Knowing why thanks to the new JSON_SCHEMA_VALIDATION_REPORT function: Copyright @ 2019 Oracle and/or its affiliates. 97 / 111
  • 98. JSON Schema validation (4) - NEW 8.0.17 And nally, mixing JSON_SCHEMA_VALID with CHECK CONSTRAINT: Copyright @ 2019 Oracle and/or its affiliates. 98 / 111
  • 99. JSON Schema validation (4) - NEW 8.0.17 And nally, mixing JSON_SCHEMA_VALID with CHECK CONSTRAINT: Copyright @ 2019 Oracle and/or its affiliates. 99 / 111
  • 100. what do I gain ? Conclusion Copyright @ 2019 Oracle and/or its affiliates. 100 / 111
  • 101. schemaless exible data structure easy to start (CRUD) Conclusion This is the best of the two worlds in one product ! Data integrity ACID Compliant Transactions SQL Copyright @ 2019 Oracle and/or its affiliates. 101 / 111
  • 103. 8.0 h ps://www.slideshare.net/lefred.descamps/mysql- shell-the-best-dba-tool h ps://github.com/lefred/mysql-shell- mydba h ps://github.com/lefred/mysql-shell- innotop More with MySQL Shell & Python Copyright @ 2019 Oracle and/or its affiliates. 103 / 111
  • 104. MySQL Shell Reporting Framework - 8.0.16 Now it's also possible to create user-de ned reports directly in the Shell. They can be wri en in Python and called the same way on every operating systems. No need for extra libraries ! More Info: h ps://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-reporting.html h ps://mysql.wisborg.dk/2019/04/26/mysql-shell-8-0-16-built-in-reports/ h ps://mysql.wisborg.dk/2019/04/27/mysql-shell-8-0-16-user-de ned-reports/ Copyright @ 2019 Oracle and/or its affiliates. 104 / 111
  • 105. MySQL Shell Extentions & Plugins - 8.0.17 Since 8.0.17, MySQL Shell has been extended to allow you to write your own extensions and plugins ! More Info: h ps://mysqlserverteam.com/mysql-shell-plugins-introduction/ h ps://lefred.be/content/overview-on-mysql-shell-8-0-17-extensions-plugins-and- how-to-write-yours/ Copyright @ 2019 Oracle and/or its affiliates. 105 / 111
  • 106. Credits Thank you Olivier Dasini for some TV Show examples: h p://dasini.net/blog/2019/04/02/mysql-json-document-store/ Thank you Jesper Wisborg Krogh for inspiration extending the MySQL Shell Copyright @ 2019 Oracle and/or its affiliates. 106 / 111
  • 108. Thank you ! Copyright @ 2019 Oracle and/or its affiliates. 108 / 111
  • 110. Upgrade to MySQL 8.0 It's time to upgrade to MySQL 8.0, the fastest MySQL adoption release ever ! Copyright @ 2019 Oracle and/or its affiliates. 110 / 111
  • 111. Session Survey Help us make the content even be er. Please complete the session survey in the Mobile App. Copyright @ 2019 Oracle and/or its affiliates. 111 / 111