SlideShare a Scribd company logo
MySQL, JSON, & You:
Perfect Together
Scott Stroz
MySQL Developer Advocate
• Developer for 20+ years
• Only constant in that stack
has been MySQL
• MySQL Developer Advocate
for Oracle
• Avid golfer
• Die hard NY Giants fan
• I have the best office mate
Obligatory "I Love Me" Slide
Copyright © 202, Oracle and/or its affiliates
2
• What is JSON?
• JSON as a string vs. JSON data type
• Why store it in database?
• How to persist JSON data
• How to retrieve JSON data
• Updating JSON data
• Using relational data as JSON
• And vice versa
• MySQL document store
What will we cover?
Photo by Ferenc Almasi on Unsplash
Copyright © 202, Oracle and/or its affiliates
3
• JSON – JavaScript Object Notation
• Textual representation of a data structure
• Objects are wrapped in { }
• Properties are key value pairs
• Keys are wrapped in " "
• Arrays are wrapped in [ ]
• Data can be nested.
• Objects can have properties that are arrays of
objects.
• Language independent
What is JSON?
Photo by Markus Spiske on Unsplash
Copyright © 202, Oracle and/or its affiliates
4
"Normalize until it hurts;
denormalize until it works."
Unknown
Copyright © 202, Oracle and/or its affiliates
5
• Faster development time
• If schema will change often, it might be better to
have no schema
• Less verbose than XML
• Pretty much every programming language can ‘read’
JSON
• Some data is unstructured
• User preferences
• Configuration data
• Feature flags
Why Store JSON?
Image by Tumisu from Pixabay
Copyright © 202, Oracle and/or its affiliates
6
JSON
Syntax
Copyright © 202, Oracle and/or its affiliates
7
• Was used long before JSON data
type
• Stored as CHAR, VARCHAR,
TEXT, etc
• Searching by values required the
use of LIKE or REGEXP
• Updating any value of the JSON
object would require rewriting the
entire string
• Introduced in MySQL 5.7
• Designed to hold valid JSON
documents.
• Stored in a binary format
• Optimized for replication & quick
searches
• Can have a defined schema
JSON as String vs. JSON DataType
JSON as String JSON DataType
Copyright © 202, Oracle and/or its affiliates
8
Creating a
Table with
JSON column
Copyright © 202, Oracle and/or its affiliates
9
Insert JSON
using…
INSERT
Copyright © 202, Oracle and/or its affiliates
10
Demo Schema
Copyright © 202, Oracle and/or its affiliates
11
Many of the JSON functions can use a 'path' to
nested data
Pathing
Copyright © 202, Oracle and/or its affiliates
12
If we want to get the keys for the 'scoring' property
we use the following:
Pathing (con't)
Copyright © 202, Oracle and/or its affiliates
13
Querying based
on JSON values
Copyright © 202, Oracle and/or its affiliates
14
JSON_CONTAINS()
Copyright © 202, Oracle and/or its affiliates
15
JSON_CONTAINS()
with strings
Copyright © 202, Oracle and/or its affiliates
16
JSON_VALUE()
Copyright © 202, Oracle and/or its affiliates
17
Using Path
Operators
Copyright © 202, Oracle and/or its affiliates
18
Updating JSON values
Copyright © 202, Oracle and/or its affiliates
19
How do we update keys/values?
JSON_INSERT()
• Inserts a new key to
a JSON document
• Will NOT update
value for existing
keys
• Can add multiple
keys in a single
statement
JSON_SET()
JSON_REPLACE()
• Inserts and updates
values in a JSON
document.
• If the key exists, the old
value is updated.
• If the key does not
exist, it is added and
the new value is used
• Updates values to
existing keys in a
JSON document
• Will NOT add key if it
does not exist
• Can update multiple
keys in a single
statement
Copyright © 202, Oracle and/or its affiliates
20
JSON_INSERT()
Copyright © 202, Oracle and/or its affiliates
21
JSON_REPLACE()
Copyright © 202, Oracle and/or its affiliates
22
JSON_SET()
Copyright © 202, Oracle and/or its affiliates
23
JSON_REMOVE()
Copyright © 202, Oracle and/or its affiliates
24
Using Relational Data as JSON
AndViceVersa
Copyright © 202, Oracle and/or its affiliates
25
Using JSON_OBJECT()
Copyright © 202, Oracle and/or its affiliates
26
Using JSON_ARRAYAGG()
Copyright © 202, Oracle and/or its affiliates
27
Returning
JSON
Data as
Relational
Data
Copyright © 202, Oracle and/or its affiliates
28
MySQL Document Store
Copyright © 202, Oracle and/or its affiliates
29
MySQL Document Store
• JSON document storage
solution built on top of MySQL
• Stored in MySQL table but
abstracted from the user
• ACID compliant
• InnoDB storage engine
• Uses JSON datatype
• Simple CRUD API
• X-Plugin
• Installed by default since 8.0.1
• Users the X Protocol through
MySQL Connectors
What is it? How can we use it?
• Node.js
• Java
• C++
• Python
• PHP
• .Net
• MySQL Shell
Copyright © 202, Oracle and/or its affiliates
30
Demo Schema
Copyright © 202, Oracle and/or its affiliates
31
Connecting to the Server
Creating a session to 'user@localhost'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 42 (X protocol)
Server version: 8.0.29 MySQL community server – GPL
No default schema selected; type use <schema> to set one
c user:password@localhost
Copyright © 202, Oracle and/or its affiliates
32
Working With Schemas
Create a Schema Use the Schema Drop the Schema
Copyright © 202, Oracle and/or its affiliates
33
Working with Collections
Create Collection Drop Collection
What the Collection Looks Like in the Database
Copyright © 202, Oracle and/or its affiliates
35
Creating Documents
Copyright © 202, Oracle and/or its affiliates
36
Searching Documents
Return All Documents Using Search Criteria
Copyright © 202, Oracle and/or its affiliates
37
Searching Documents
Sort Results Limit Results Offset Results
Copyright © 202, Oracle and/or its affiliates
38
What is returned?
Copyright © 202, Oracle and/or its affiliates
39
Returning Specific Keys
Copyright © 202, Oracle and/or its affiliates
40
What is returned?
Copyright © 202, Oracle and/or its affiliates
41
Grouping Results
Copyright © 202, Oracle and/or its affiliates
42
What is returned?
Copyright © 202, Oracle and/or its affiliates
43
Using SQL with Document Store
Copyright © 202, Oracle and/or its affiliates
44
What is
returned?
Copyright © 202, Oracle and/or its affiliates
45
RECAP
• WE DEFINED JSON ANDTALKED ABOUT SYNTAX.
• JSON AS A STRINGVS. JSON DATATYPE
• WHY STORE IT IN DATABASE?
• HOWTO PERSIST JSON DATA
• HOWTO RETRIEVE JSON DATA
• UPDATING JSON DATA
• USING RELATIONAL DATA AS JSON
• USING JSON AS RELATIONAL DATA
• MYSQL DOCUMENT STORE
Copyright © 202, Oracle and/or its affiliates
46
Resources
GitHub
• https://github.com/boyzoid/mysql-json-demo
MySQL Documentation
• https://dev.mysql.com/doc/refman/8.0/en/json-function-reference.html
• https://dev.mysql.com/doc/refman/8.0/en/document-store-concepts.html
David Stokes' book
• MySQL & JSON: A Practical Programming Guide
Copyright © 202, Oracle and/or its affiliates
47

More Related Content

Similar to Data Con LA 2022 - MySQL, JSON & You: Perfect Together

MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
Frederic Descamps
 
Java EE 7 overview
Java EE 7 overviewJava EE 7 overview
Java EE 7 overview
Masoud Kalali
 
Mongo DB
Mongo DB Mongo DB
REST Enabling Your Oracle Database
REST Enabling Your Oracle DatabaseREST Enabling Your Oracle Database
REST Enabling Your Oracle Database
Jeff Smith
 
Configuration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and TamayaConfiguration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and Tamaya
Dmitry Kornilov
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
Teamstudio
 
Power JSON with PostgreSQL
Power JSON with PostgreSQLPower JSON with PostgreSQL
Power JSON with PostgreSQL
EDB
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug Madrid
Vinay Kumar
 
MySQL 8 loves JavaScript
MySQL 8 loves JavaScript MySQL 8 loves JavaScript
MySQL 8 loves JavaScript
Sanjay Manwani
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
Anekwong Yoddumnern
 
JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database
Yolande Poirier
 
Python and the MySQL Document Store
Python and the MySQL Document StorePython and the MySQL Document Store
Python and the MySQL Document Store
Jesper Wisborg Krogh
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle Database
Maria Colgan
 
Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0
Frederic Descamps
 
Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016
Dave Stokes
 
War of the Indices- SQL vs. Oracle
War of the Indices-  SQL vs. OracleWar of the Indices-  SQL vs. Oracle
War of the Indices- SQL vs. Oracle
Kellyn Pot'Vin-Gorman
 
Sql Server 2016 and JSON
Sql Server 2016 and JSONSql Server 2016 and JSON
Sql Server 2016 and JSON
Greg McMurray
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
rchakra
 
MySQL como Document Store PHP Conference 2017
MySQL como Document Store PHP Conference 2017MySQL como Document Store PHP Conference 2017
MySQL como Document Store PHP Conference 2017
MySQL Brasil
 
Ado
AdoAdo

Similar to Data Con LA 2022 - MySQL, JSON & You: Perfect Together (20)

MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
 
Java EE 7 overview
Java EE 7 overviewJava EE 7 overview
Java EE 7 overview
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
REST Enabling Your Oracle Database
REST Enabling Your Oracle DatabaseREST Enabling Your Oracle Database
REST Enabling Your Oracle Database
 
Configuration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and TamayaConfiguration for Java EE: Config JSR and Tamaya
Configuration for Java EE: Config JSR and Tamaya
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Power JSON with PostgreSQL
Power JSON with PostgreSQLPower JSON with PostgreSQL
Power JSON with PostgreSQL
 
Expose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug MadridExpose your data as an api is with oracle rest data services -spoug Madrid
Expose your data as an api is with oracle rest data services -spoug Madrid
 
MySQL 8 loves JavaScript
MySQL 8 loves JavaScript MySQL 8 loves JavaScript
MySQL 8 loves JavaScript
 
ADO.NET -database connection
ADO.NET -database connectionADO.NET -database connection
ADO.NET -database connection
 
JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database JDBC Next: A New Asynchronous API for Connecting to a Database
JDBC Next: A New Asynchronous API for Connecting to a Database
 
Python and the MySQL Document Store
Python and the MySQL Document StorePython and the MySQL Document Store
Python and the MySQL Document Store
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle Database
 
Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0Les nouveautés de MySQL 8.0
Les nouveautés de MySQL 8.0
 
Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016Polyglot Database - Linuxcon North America 2016
Polyglot Database - Linuxcon North America 2016
 
War of the Indices- SQL vs. Oracle
War of the Indices-  SQL vs. OracleWar of the Indices-  SQL vs. Oracle
War of the Indices- SQL vs. Oracle
 
Sql Server 2016 and JSON
Sql Server 2016 and JSONSql Server 2016 and JSON
Sql Server 2016 and JSON
 
Introduction to ADO.NET
Introduction to ADO.NETIntroduction to ADO.NET
Introduction to ADO.NET
 
MySQL como Document Store PHP Conference 2017
MySQL como Document Store PHP Conference 2017MySQL como Document Store PHP Conference 2017
MySQL como Document Store PHP Conference 2017
 
Ado
AdoAdo
Ado
 

More from Data Con LA

Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 Keynotes
Data Con LA
 
Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 Keynotes
Data Con LA
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 Keynote
Data Con LA
 
Data Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup ShowcaseData Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup Showcase
Data Con LA
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 Keynote
Data Con LA
 
Data Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendationsData Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA
 
Data Con LA 2022 - AI Ethics
Data Con LA 2022 - AI EthicsData Con LA 2022 - AI Ethics
Data Con LA 2022 - AI Ethics
Data Con LA
 
Data Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learningData Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learning
Data Con LA
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA
 
Data Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentationData Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentation
Data Con LA
 
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA
 
Data Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWSData Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWS
Data Con LA
 
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AIData Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA
 
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA
 
Data Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data ScienceData Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data Science
Data Con LA
 
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing EntertainmentData Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA
 
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA
 
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA
 
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA
 
Data Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with KafkaData Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with Kafka
Data Con LA
 

More from Data Con LA (20)

Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 Keynotes
 
Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 Keynotes
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 Keynote
 
Data Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup ShowcaseData Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup Showcase
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 Keynote
 
Data Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendationsData Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendations
 
Data Con LA 2022 - AI Ethics
Data Con LA 2022 - AI EthicsData Con LA 2022 - AI Ethics
Data Con LA 2022 - AI Ethics
 
Data Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learningData Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learning
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
 
Data Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentationData Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentation
 
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
 
Data Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWSData Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWS
 
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AIData Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
 
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
 
Data Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data ScienceData Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data Science
 
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing EntertainmentData Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
 
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
 
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
 
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
 
Data Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with KafkaData Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with Kafka
 

Recently uploaded

一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
Social Samosa
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
u86oixdj
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
dwreak4tg
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
g4dpvqap0
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
kuntobimo2016
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 

Recently uploaded (20)

一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 

Data Con LA 2022 - MySQL, JSON & You: Perfect Together

  • 1. MySQL, JSON, & You: Perfect Together Scott Stroz MySQL Developer Advocate
  • 2. • Developer for 20+ years • Only constant in that stack has been MySQL • MySQL Developer Advocate for Oracle • Avid golfer • Die hard NY Giants fan • I have the best office mate Obligatory "I Love Me" Slide Copyright © 202, Oracle and/or its affiliates 2
  • 3. • What is JSON? • JSON as a string vs. JSON data type • Why store it in database? • How to persist JSON data • How to retrieve JSON data • Updating JSON data • Using relational data as JSON • And vice versa • MySQL document store What will we cover? Photo by Ferenc Almasi on Unsplash Copyright © 202, Oracle and/or its affiliates 3
  • 4. • JSON – JavaScript Object Notation • Textual representation of a data structure • Objects are wrapped in { } • Properties are key value pairs • Keys are wrapped in " " • Arrays are wrapped in [ ] • Data can be nested. • Objects can have properties that are arrays of objects. • Language independent What is JSON? Photo by Markus Spiske on Unsplash Copyright © 202, Oracle and/or its affiliates 4
  • 5. "Normalize until it hurts; denormalize until it works." Unknown Copyright © 202, Oracle and/or its affiliates 5
  • 6. • Faster development time • If schema will change often, it might be better to have no schema • Less verbose than XML • Pretty much every programming language can ‘read’ JSON • Some data is unstructured • User preferences • Configuration data • Feature flags Why Store JSON? Image by Tumisu from Pixabay Copyright © 202, Oracle and/or its affiliates 6
  • 7. JSON Syntax Copyright © 202, Oracle and/or its affiliates 7
  • 8. • Was used long before JSON data type • Stored as CHAR, VARCHAR, TEXT, etc • Searching by values required the use of LIKE or REGEXP • Updating any value of the JSON object would require rewriting the entire string • Introduced in MySQL 5.7 • Designed to hold valid JSON documents. • Stored in a binary format • Optimized for replication & quick searches • Can have a defined schema JSON as String vs. JSON DataType JSON as String JSON DataType Copyright © 202, Oracle and/or its affiliates 8
  • 9. Creating a Table with JSON column Copyright © 202, Oracle and/or its affiliates 9
  • 10. Insert JSON using… INSERT Copyright © 202, Oracle and/or its affiliates 10
  • 11. Demo Schema Copyright © 202, Oracle and/or its affiliates 11
  • 12. Many of the JSON functions can use a 'path' to nested data Pathing Copyright © 202, Oracle and/or its affiliates 12
  • 13. If we want to get the keys for the 'scoring' property we use the following: Pathing (con't) Copyright © 202, Oracle and/or its affiliates 13
  • 14. Querying based on JSON values Copyright © 202, Oracle and/or its affiliates 14
  • 15. JSON_CONTAINS() Copyright © 202, Oracle and/or its affiliates 15
  • 16. JSON_CONTAINS() with strings Copyright © 202, Oracle and/or its affiliates 16
  • 17. JSON_VALUE() Copyright © 202, Oracle and/or its affiliates 17
  • 18. Using Path Operators Copyright © 202, Oracle and/or its affiliates 18
  • 19. Updating JSON values Copyright © 202, Oracle and/or its affiliates 19
  • 20. How do we update keys/values? JSON_INSERT() • Inserts a new key to a JSON document • Will NOT update value for existing keys • Can add multiple keys in a single statement JSON_SET() JSON_REPLACE() • Inserts and updates values in a JSON document. • If the key exists, the old value is updated. • If the key does not exist, it is added and the new value is used • Updates values to existing keys in a JSON document • Will NOT add key if it does not exist • Can update multiple keys in a single statement Copyright © 202, Oracle and/or its affiliates 20
  • 21. JSON_INSERT() Copyright © 202, Oracle and/or its affiliates 21
  • 22. JSON_REPLACE() Copyright © 202, Oracle and/or its affiliates 22
  • 23. JSON_SET() Copyright © 202, Oracle and/or its affiliates 23
  • 24. JSON_REMOVE() Copyright © 202, Oracle and/or its affiliates 24
  • 25. Using Relational Data as JSON AndViceVersa Copyright © 202, Oracle and/or its affiliates 25
  • 26. Using JSON_OBJECT() Copyright © 202, Oracle and/or its affiliates 26
  • 27. Using JSON_ARRAYAGG() Copyright © 202, Oracle and/or its affiliates 27
  • 28. Returning JSON Data as Relational Data Copyright © 202, Oracle and/or its affiliates 28
  • 29. MySQL Document Store Copyright © 202, Oracle and/or its affiliates 29
  • 30. MySQL Document Store • JSON document storage solution built on top of MySQL • Stored in MySQL table but abstracted from the user • ACID compliant • InnoDB storage engine • Uses JSON datatype • Simple CRUD API • X-Plugin • Installed by default since 8.0.1 • Users the X Protocol through MySQL Connectors What is it? How can we use it? • Node.js • Java • C++ • Python • PHP • .Net • MySQL Shell Copyright © 202, Oracle and/or its affiliates 30
  • 31. Demo Schema Copyright © 202, Oracle and/or its affiliates 31
  • 32. Connecting to the Server Creating a session to 'user@localhost' Fetching schema names for autocompletion... Press ^C to stop. Your MySQL connection id is 42 (X protocol) Server version: 8.0.29 MySQL community server – GPL No default schema selected; type use <schema> to set one c user:password@localhost Copyright © 202, Oracle and/or its affiliates 32
  • 33. Working With Schemas Create a Schema Use the Schema Drop the Schema Copyright © 202, Oracle and/or its affiliates 33
  • 34. Working with Collections Create Collection Drop Collection
  • 35. What the Collection Looks Like in the Database Copyright © 202, Oracle and/or its affiliates 35
  • 36. Creating Documents Copyright © 202, Oracle and/or its affiliates 36
  • 37. Searching Documents Return All Documents Using Search Criteria Copyright © 202, Oracle and/or its affiliates 37
  • 38. Searching Documents Sort Results Limit Results Offset Results Copyright © 202, Oracle and/or its affiliates 38
  • 39. What is returned? Copyright © 202, Oracle and/or its affiliates 39
  • 40. Returning Specific Keys Copyright © 202, Oracle and/or its affiliates 40
  • 41. What is returned? Copyright © 202, Oracle and/or its affiliates 41
  • 42. Grouping Results Copyright © 202, Oracle and/or its affiliates 42
  • 43. What is returned? Copyright © 202, Oracle and/or its affiliates 43
  • 44. Using SQL with Document Store Copyright © 202, Oracle and/or its affiliates 44
  • 45. What is returned? Copyright © 202, Oracle and/or its affiliates 45
  • 46. RECAP • WE DEFINED JSON ANDTALKED ABOUT SYNTAX. • JSON AS A STRINGVS. JSON DATATYPE • WHY STORE IT IN DATABASE? • HOWTO PERSIST JSON DATA • HOWTO RETRIEVE JSON DATA • UPDATING JSON DATA • USING RELATIONAL DATA AS JSON • USING JSON AS RELATIONAL DATA • MYSQL DOCUMENT STORE Copyright © 202, Oracle and/or its affiliates 46
  • 47. Resources GitHub • https://github.com/boyzoid/mysql-json-demo MySQL Documentation • https://dev.mysql.com/doc/refman/8.0/en/json-function-reference.html • https://dev.mysql.com/doc/refman/8.0/en/document-store-concepts.html David Stokes' book • MySQL & JSON: A Practical Programming Guide Copyright © 202, Oracle and/or its affiliates 47

Editor's Notes

  1. When using JSON_CONTAINS() to search for a string, we need to double quote the value. JSON_TABLE() lets you extract data from JSON and treat it as a table. JSON_ARRAYAGG() can be used to aggregate values into an array. The result has a JSON array, some with multiple values.
  2. Can return not only the value, but can be CAST to different data types.
  3. Column path operator = -> and will keep the quotes around values Inline path operator = ->> and removes quotes
  4. Commands are all for MySQL Shell. Syntax slightly different for other connectors.
  5. Adding a single document. Add multiple by passing an array of documents.
  6. 1 CTE for all scores 2 CTE for low score on each course 3 Begin main query 4 Create array of golfers with the same score.