SlideShare a Scribd company logo
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
MySQL Document Store dirigido a
Desarrolladores
Keith Hollman
MySQL Principal Solution Architect
keith.hollman@oracle.com
DEMO
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes 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 upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Install MySQL 8.0
$ export PATH=$PATH:/usr/local/mysql/mysql-shell-commercial-8.0.11-linux-
glibc2.12-x86-64bit/bin:/usr/local/mysql/mysql-commercial-8.0.11-linux-
glibc2.12-x86_64/bin
$ cd /usr/local/mysql/mysql-commercial-8.0.11-linux-glibc2.12-x86_64/bin
$ mysqld --defaults-file=my.cnf --initialize-insecure
$ mysqld --defaults-file=my.cnf &
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Download & install Mongo
$ tar zxvf mongodb-linux-x86_64-4.0.0.tar.gz
$ cd /usr/local/mongodb-linux-x86_64-4.0.0
$ export PATH=$PATH:/usr/local/mongodb-linux-x86_64-4.0.0/bin
$ mkdir -p /opt/mongo/data mongo/log
$ vi mongod.conf
systemLog:
destination: file
path: "/opt/mongo/log/mongod.log"
logAppend: true
storage:
dbPath: "/opt/mongo/data"
...
$ mongod --config /usr/local/mongodb-linux-x86_64-4.0.0/mongod.conf
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Download data to import into mongo
• https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/index.html
• File to be downloaded is:
– https://raw.githubusercontent.com/mongodb/docs-
assets/geospatial/restaurants.json
$ mongoimport DocStore/demo/restaurants.json -c restaurants
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Export data for importing into MySQL
• This example is inspired by @datacharmer's work:
https://www.slideshare.net/datacharmer/mysql-documentstore
• And also:
https://www.slideshare.net/lefred.descamps/mysql-document-store-how-to-replace-a-
nosql-database-by-mysql-without-effort-but-with-a-lot-gains
$ mongo --quiet --eval 'DBQuery.shellBatchSize=30000; 
db.restaurants.find().shellPrint()' 
| perl -pe 's/(?:ObjectId|ISODate)(("[^"]+"))/ $1/g' 
> DocStore/demo/all_recs.json
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
• Before we start loading data, let's
tail the general_log:
$ cd /opt/mysql/8011/data
$ tail -100f tail -100f
khollman_8011.log
• Create the environment within
MySQL:
$ cd DocStore/demo
$ mysqlsh --uri root@localhost
session.createSchema('test')
use test
db.createCollection('restaurants')
py
import json
import re
with open ('all_recs.json', 'r') as
json_data:
for line in json_data:
skip = re.match('Type', line)
if not skip:
rec = json.loads(line)
db.restaurants.add(rec).execute()
Loading data into MySQL
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
• Now the data is imported, let's
query it:
db.restaurants.find()
db.restaurants.find().limit(1)
db.restaurants.find().fields(["_id","na
me","cuisine"]).limit(2)
• Using sql still? For whatever reason:
session.sql("show create table
restaurants")
session.sql("select * from
restaurants")
session.sql("select * from restaurants
limit 2")
• Let's update an attribute of the
collection, using the id:
db.restaurants.modify("_id='55cba2476c
522cafdb053add'").set("cuisine","Itali
an")
db.restaurants.find("_id='55cba2476c52
2cafdb053add'")
Querying data
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Querying data (cont.)
• We're ACID, and can still do transactions:
session.startTransaction()
db.restaurants.remove("_id='55cba2476c522cafdb053add'")
db.restaurants.find("_id='55cba2476c522cafdb053add'")
db.restaurants.modify("_id ='55cba2476c522cafdb053ade'").set("name", "The
Hybrid Lunch")
db.restaurants.find("_id = '55cba2476c522cafdb053ade'")
session.rollback()
db.restaurants.find("_id='55cba2476c522cafdb053add'")
db.restaurants.find("_id = '55cba2476c522cafdb053ade'")
• Using SQL and formatting:
SELECT doc->>"$.name" AS name, doc->>"$.cuisine" AS cuisine FROM restaurants
where doc->>"$.cuisine" is not null;
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
• Getting data out of the Collection,
dynamically:
ALTER TABLE restaurants ADD COLUMN
borough VARCHAR(20) GENERATED ALWAYS
AS
(json_unquote(json_extract(`doc`,'$.bo
rough'))) VIRTUAL;
• same as:
ALTER TABLE restaurants ADD COLUMN
borough VARCHAR(20) GENERATED ALWAYS
AS
(doc->>"$.borough") VIRTUAL;
• Using MySQL 8.0 CTE:
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 restaurants) SELECT
*, RANK() OVER (PARTITION BY cuisine
ORDER BY avg_score) AS `rank`
FROM cte1 ORDER BY `rank`, avg_score
DESC LIMIT 30;
Querying data (cont.)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
More examples & Information
• https://elephantdolphin.blogspot.com/2018/06/mongodb-versus-mysql-
document-store.html
• https://mysqlserverteam.com/mysql-8-0-from-sql-tables-to-json-
documents-and-back-again/
• https://www.mysql.com/news-and-events/web-seminars/nosql-
development-for-mysql-document-store-using-java/
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Preguntas?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
MySQL NoSQL JSON JS Python "Document Store" demo

More Related Content

PPTX
State ofdolphin short
PDF
MySQL partitioning
PDF
Solving Performance Problems Using MySQL Enterprise Monitor
PDF
Develop Python Applications with MySQL Connector/Python
PDF
MySQL 8.0 InnoDB Cluster demo
PDF
Bye bye $GLOBALS['TYPO3_DB']
PPTX
MySQL 8.0 Released Update
PDF
MySQL Enterprise Backup - BnR Scenarios
State ofdolphin short
MySQL partitioning
Solving Performance Problems Using MySQL Enterprise Monitor
Develop Python Applications with MySQL Connector/Python
MySQL 8.0 InnoDB Cluster demo
Bye bye $GLOBALS['TYPO3_DB']
MySQL 8.0 Released Update
MySQL Enterprise Backup - BnR Scenarios

What's hot (20)

PPTX
MySQL in oracle_environments(Part 2): MySQL Enterprise Monitor & Oracle Enter...
PPTX
Simple Way for MySQL to NoSQL
PDF
The MySQL SYS Schema
PDF
MySQL Technology Overview
PPT
MySQL in Oracle environment : Quick start guide for Oracle DBA (Part 1)
PDF
Introduction to Apache Hive
ODP
Introduction to MySQL Enterprise Monitor
PPT
How to integrate Splunk with any data solution
PPTX
Ingesting streaming data for analysis in apache ignite (stream sets theme)
PPTX
DataStax | Deploy DataStax Enterprise Clusters with OpsCenter (LCM) (Manikand...
ODP
MySQL Monitoring Mechanisms
PDF
MySQL Server Defaults
PDF
Mysql tech day_paris_ps_and_sys
PPTX
Quick MySQL performance check
PPSX
implementation of a big data architecture for real-time analytics with data s...
PDF
How to Find Patterns in Your Data with SQL
PDF
MySQL Enterprise Edition - Complete Guide (2019)
PDF
Upgrade your javascript to drupal 8
PDF
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
PPTX
Protecting your data from SQL Injection attacks
MySQL in oracle_environments(Part 2): MySQL Enterprise Monitor & Oracle Enter...
Simple Way for MySQL to NoSQL
The MySQL SYS Schema
MySQL Technology Overview
MySQL in Oracle environment : Quick start guide for Oracle DBA (Part 1)
Introduction to Apache Hive
Introduction to MySQL Enterprise Monitor
How to integrate Splunk with any data solution
Ingesting streaming data for analysis in apache ignite (stream sets theme)
DataStax | Deploy DataStax Enterprise Clusters with OpsCenter (LCM) (Manikand...
MySQL Monitoring Mechanisms
MySQL Server Defaults
Mysql tech day_paris_ps_and_sys
Quick MySQL performance check
implementation of a big data architecture for real-time analytics with data s...
How to Find Patterns in Your Data with SQL
MySQL Enterprise Edition - Complete Guide (2019)
Upgrade your javascript to drupal 8
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Protecting your data from SQL Injection attacks
Ad

Similar to MySQL NoSQL JSON JS Python "Document Store" demo (20)

PDF
20160821 coscup-my sql57docstorelab01
PDF
Python and the MySQL Document Store
PDF
MySQL Document Store
PDF
MySQL Document Store (Oracle Code Warsaw 2018)
PDF
MySQL Day Paris 2018 - What’s New in MySQL 8.0 ?
PDF
MySQL Document Store - A Document Store with all the benefts of a Transactona...
PDF
20201106 hk-py con-mysql-shell
PDF
MySQL 8.0 - What's New ?
PPTX
2018: State of the Dolphin, MySQL Keynote at Percona Live Europe 2018, Frankf...
PDF
No, wait, not that way! - Real-world lessons from an OBIA 11g implementation
PDF
20151010 my sq-landjavav2a
PDF
20190713_MySQL開発最新動向
PDF
Node.js and the MySQL Document Store
PDF
Oracle Code Event - MySQL JSON Document Store
PDF
MySQL Shell - The Best MySQL DBA Tool
PDF
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
PDF
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
PDF
MySQL For Oracle Developers
PDF
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
PPTX
2019 indit blackhat_honeypot your database server
20160821 coscup-my sql57docstorelab01
Python and the MySQL Document Store
MySQL Document Store
MySQL Document Store (Oracle Code Warsaw 2018)
MySQL Day Paris 2018 - What’s New in MySQL 8.0 ?
MySQL Document Store - A Document Store with all the benefts of a Transactona...
20201106 hk-py con-mysql-shell
MySQL 8.0 - What's New ?
2018: State of the Dolphin, MySQL Keynote at Percona Live Europe 2018, Frankf...
No, wait, not that way! - Real-world lessons from an OBIA 11g implementation
20151010 my sq-landjavav2a
20190713_MySQL開発最新動向
Node.js and the MySQL Document Store
Oracle Code Event - MySQL JSON Document Store
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
MySQL For Oracle Developers
[OSC 2020 Online/Nagoya] MySQLドキュメントストア
2019 indit blackhat_honeypot your database server
Ad

More from Keith Hollman (9)

PDF
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
PDF
MySQL InnoDB Cluster HA Overview & Demo
PDF
MySQL Cluster: El ‘qué’ y el ‘cómo’.
PDF
MySQL Replication: Demo Réplica en Español
PDF
Meb Backup & Recovery Performance
PPT
MySQL Una Introduccion Tecnica
PDF
MySQL Enterprise Backup: PITR Partial Online Recovery
PDF
A MySQL Odyssey - A Blackhole Crossover
PDF
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
MySQL InnoDB Cluster HA Overview & Demo
MySQL Cluster: El ‘qué’ y el ‘cómo’.
MySQL Replication: Demo Réplica en Español
Meb Backup & Recovery Performance
MySQL Una Introduccion Tecnica
MySQL Enterprise Backup: PITR Partial Online Recovery
A MySQL Odyssey - A Blackhole Crossover
Embracing Database Diversity: The New Oracle / MySQL DBA - UKOUG

Recently uploaded (20)

PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
Computer network topology notes for revision
PPT
Reliability_Chapter_ presentation 1221.5784
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
1_Introduction to advance data techniques.pptx
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PDF
Lecture1 pattern recognition............
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
PPTX
Introduction to Knowledge Engineering Part 1
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
Database Infoormation System (DBIS).pptx
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Computer network topology notes for revision
Reliability_Chapter_ presentation 1221.5784
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
climate analysis of Dhaka ,Banglades.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Galatica Smart Energy Infrastructure Startup Pitch Deck
IBA_Chapter_11_Slides_Final_Accessible.pptx
1_Introduction to advance data techniques.pptx
Clinical guidelines as a resource for EBP(1).pdf
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
Lecture1 pattern recognition............
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
Introduction to Knowledge Engineering Part 1
Data_Analytics_and_PowerBI_Presentation.pptx
Supervised vs unsupervised machine learning algorithms
Database Infoormation System (DBIS).pptx

MySQL NoSQL JSON JS Python "Document Store" demo

  • 1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | MySQL Document Store dirigido a Desarrolladores Keith Hollman MySQL Principal Solution Architect keith.hollman@oracle.com DEMO
  • 2. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes 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 upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 3. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Install MySQL 8.0 $ export PATH=$PATH:/usr/local/mysql/mysql-shell-commercial-8.0.11-linux- glibc2.12-x86-64bit/bin:/usr/local/mysql/mysql-commercial-8.0.11-linux- glibc2.12-x86_64/bin $ cd /usr/local/mysql/mysql-commercial-8.0.11-linux-glibc2.12-x86_64/bin $ mysqld --defaults-file=my.cnf --initialize-insecure $ mysqld --defaults-file=my.cnf &
  • 4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Download & install Mongo $ tar zxvf mongodb-linux-x86_64-4.0.0.tar.gz $ cd /usr/local/mongodb-linux-x86_64-4.0.0 $ export PATH=$PATH:/usr/local/mongodb-linux-x86_64-4.0.0/bin $ mkdir -p /opt/mongo/data mongo/log $ vi mongod.conf systemLog: destination: file path: "/opt/mongo/log/mongod.log" logAppend: true storage: dbPath: "/opt/mongo/data" ... $ mongod --config /usr/local/mongodb-linux-x86_64-4.0.0/mongod.conf
  • 5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Download data to import into mongo • https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/index.html • File to be downloaded is: – https://raw.githubusercontent.com/mongodb/docs- assets/geospatial/restaurants.json $ mongoimport DocStore/demo/restaurants.json -c restaurants
  • 6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Export data for importing into MySQL • This example is inspired by @datacharmer's work: https://www.slideshare.net/datacharmer/mysql-documentstore • And also: https://www.slideshare.net/lefred.descamps/mysql-document-store-how-to-replace-a- nosql-database-by-mysql-without-effort-but-with-a-lot-gains $ mongo --quiet --eval 'DBQuery.shellBatchSize=30000; db.restaurants.find().shellPrint()' | perl -pe 's/(?:ObjectId|ISODate)(("[^"]+"))/ $1/g' > DocStore/demo/all_recs.json
  • 7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | • Before we start loading data, let's tail the general_log: $ cd /opt/mysql/8011/data $ tail -100f tail -100f khollman_8011.log • Create the environment within MySQL: $ cd DocStore/demo $ mysqlsh --uri root@localhost session.createSchema('test') use test db.createCollection('restaurants') py import json import re with open ('all_recs.json', 'r') as json_data: for line in json_data: skip = re.match('Type', line) if not skip: rec = json.loads(line) db.restaurants.add(rec).execute() Loading data into MySQL
  • 8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | • Now the data is imported, let's query it: db.restaurants.find() db.restaurants.find().limit(1) db.restaurants.find().fields(["_id","na me","cuisine"]).limit(2) • Using sql still? For whatever reason: session.sql("show create table restaurants") session.sql("select * from restaurants") session.sql("select * from restaurants limit 2") • Let's update an attribute of the collection, using the id: db.restaurants.modify("_id='55cba2476c 522cafdb053add'").set("cuisine","Itali an") db.restaurants.find("_id='55cba2476c52 2cafdb053add'") Querying data
  • 9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Querying data (cont.) • We're ACID, and can still do transactions: session.startTransaction() db.restaurants.remove("_id='55cba2476c522cafdb053add'") db.restaurants.find("_id='55cba2476c522cafdb053add'") db.restaurants.modify("_id ='55cba2476c522cafdb053ade'").set("name", "The Hybrid Lunch") db.restaurants.find("_id = '55cba2476c522cafdb053ade'") session.rollback() db.restaurants.find("_id='55cba2476c522cafdb053add'") db.restaurants.find("_id = '55cba2476c522cafdb053ade'") • Using SQL and formatting: SELECT doc->>"$.name" AS name, doc->>"$.cuisine" AS cuisine FROM restaurants where doc->>"$.cuisine" is not null;
  • 10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | • Getting data out of the Collection, dynamically: ALTER TABLE restaurants ADD COLUMN borough VARCHAR(20) GENERATED ALWAYS AS (json_unquote(json_extract(`doc`,'$.bo rough'))) VIRTUAL; • same as: ALTER TABLE restaurants ADD COLUMN borough VARCHAR(20) GENERATED ALWAYS AS (doc->>"$.borough") VIRTUAL; • Using MySQL 8.0 CTE: 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 restaurants) SELECT *, RANK() OVER (PARTITION BY cuisine ORDER BY avg_score) AS `rank` FROM cte1 ORDER BY `rank`, avg_score DESC LIMIT 30; Querying data (cont.)
  • 11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | More examples & Information • https://elephantdolphin.blogspot.com/2018/06/mongodb-versus-mysql- document-store.html • https://mysqlserverteam.com/mysql-8-0-from-sql-tables-to-json- documents-and-back-again/ • https://www.mysql.com/news-and-events/web-seminars/nosql- development-for-mysql-document-store-using-java/
  • 12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | Preguntas?
  • 13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |