SlideShare a Scribd company logo
1 of 43
Download to read offline
MySQl aS A
dOCUMENTSTORE
David.Stokes@Oracle.com @ Stoker
slideshare.net/davidmstokes
elelphantanddolphin.blogger.com
"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."
Safe Harbor
2
Hello!I am Dave Stokes, MySQL Community Manager
David.Stokes@Oracle.com @Stoker
Slides at Slideshare.net/davidmstokes
Blogs: Opensourcedba.wordpress.com
elephantanddolphin.blogger.com 3
1.
Json & json dATATYPE
MySQL 5.7
4
“JSON JavaScript Object
Notation is a lightweight
data-interchange format. It
is built on two structures:
A collection of name/vaule
pairs and and ordered list
of values.”
5
MySQL JSON data type
× Schemaless data
× UTF8MB4
× It is just like a INT, or REAL, or TIMESTAMP. You
can store an entire document in a column of a
row of a table.
You could store JSON in a CHAR/TEXT field but it is
not sexy and you end up using REGEXP --- Ughhh!
6
Big
Very few developers are learning SQL (Structured
Query Language), Relational Theory, Sets, data
normalization or other database related subjects!
7
SQL
Data is normalized and
formats are rigorously
enforced. JOIN and logical
operators allow complex
queries. Costly to change
schema.
The big contest of 2014 In case you missed it
NoSQL
Schemaless, no need for
relational overhead,
changes as fast as the
data, easy to implement.
8
MySQl offers both SQL & NoSQL
RDMS
Good old relational
database
InnoDB/Memcached
This plug-in allows
direct access to
InnoDB or NDB
storage engine data
using the
memcached
protocol, up to 9x
faster
JSON
Data is stored in
JSON format. No
schema needed.
Functions supplied
for SQL based
access &
manipulation
9
But what if you
wanted a database
but do not know
sql?
10
New
Definitions
11
12
JSON Documents and Collections
A JSON document is a data structure
composed of field/value pairs stored
within a collection. The values of fields
often contain other documents, arrays,
and lists of documents.
CRUD
Operations
Create, Read, Update and
Delete (CRUD) operations are
the four basic operations that
can be performed on a
database Collection or Table
13
X Protocol
The X Protocol supports both
CRUD and SQL operations,
authentication via SASL,
allows streaming (pipelining)
of commands and is extensible
on the protocol and the
message layer.
14
Mysqlsh has three modes
js -- JavaScript
py -- python
SQL -- SQL (like old
Mysql shell)
15
1. MySQL 5.17.12 or later
2. Install X plugin
a. mysql> INSTALL PLUGINmysqlx SONAME
“mysqlx.so”; OR
b. mysqlsh -u user -h localhost --classic --dba
enableXProtocol
3. Install mysqlsh *
16
Installation needs
● Note: Installation of
MySQL Shell using the
MySQL APT repository is
only supported on Ubuntu
14.04 LTS (“Trusty Tahr”)
and Ubuntu 15.10 (“Wily
Werewolf”).
mysqlsh
$ mysqlsh --uri dstokes:hidave@localhost world_x --node
mysqlx: [Warning] Using a password on the command line interface can be insecure.
Creating a Node Session to dstokes@localhost:33060/world_x
Default schema `world_x` accessible through db.
Welcome to MySQL Shell 1.0.5 Development Preview
Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help', 'h' or '?' for help, type 'quit' or 'q' to exit.
Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries.
mysql-js>
17
MySQLSh shell Sessions
MySQL Shell is a unified interface
to operate MySQL Server through
scripting languages such as
JavaScript or Python. To maintain
compatibility with previous
versions, SQL can also be
executed in certain modes. A
connection to a MySQL server is
required. In MySQL Shell these
connections are handled by a
Session object.
18
XSession: Use this session type for new
application development. It offers the
best integration with MySQL Server, and
therefore, it is used by default. SQL
execution is not supported
Node Session: Use this session type for
SQL execution on a MySQL Server with
the X Protocol enabled. SQL execution
is available
Classic Session Use this session type to
interact with MySQL Servers that do not
have the X Protocol enabled
● --node creates a Node Session.
● --classic creates a Classic Session.
● --x creates an XSession.
session
mysql-js> session
<NodeSession:dstokes@localhost:33060/world_x>
mysql-js>
The above tells us we are a JavaScript mode
Account is dstokes@localhost on port 33060
The Database/schema is world_x
19
session
mysql-js> session
<NodeSession:dstokes@localhost:33060/world_x>
mysql-js>
The above tells us we are a JavaScript mode
Account is dstokes@localhost on port 33060
The Database/schema is world_x
20
WHICH DATABASE AND WHICH COLLECTION
mysql-js> db
<Schema:world_x>
mysql-js> db.getCollections()
[
<Collection:countryinfo>
]
mysql-js>
21
<-- The Database
← the table
Batch Mode Example
22
echo "SELECT * FROM world_x.city LIMIT 2;" | mysqlsh --json=pretty --sqlc --uri user@host
{
"executionTime": "0.00 sec",
"info": "",
"rows": [
{
"ID": 1,
"Name": "Kabul",
"CountryCode": "AFG",
"District": "Kabol",
"Info": "{"Population": 1780000}"
},
{
"ID": 2,
"Name": "Qandahar",
"CountryCode": "AFG",
"District": "Qandahar",
"Info": "{"Population": 237500}"
}
],
"warningCount": 0,
"warnings": [],
"hasData": true,
"affectedRowCount": 0,
"autoIncrementValue": 0
}
This is a batch mode
example where a query is
sent to mysqlsh in sql mode
and the output is produced
in ‘pretty’ JSON format.
Interactive help
mysql-js> var mySchema =
session.getSchema('Zendcon')
The schema Zendcon does not
exist, do you want to create it?
[y/N]: y
mysql-js> mySchema
<Schema:Zendcon>
mysql-js>
Note the interactive error
correction when a non
existent schema is
accessed.
23
db
24
$ mysqlsh --uri dstokes:hidave@localhost world_x
Default schema `world_x` accessible through db.
...
mysql-js> db
<Schema:world_x>
mysql-js> db.getCollections()
[
<Collection:countryinfo>
]
mysql-js> db.countryinfo.find().limit(1)
[
{
"GNP": 828,
"IndepYear": null,
"Name": "Aruba" ….
db is a global variable
assigned to the current
active schema that you
specified on the command
line.
Basic Operators
25
db.name.add()
The add() method inserts one document or a list of documents into the named collection.
db.name.find()
The find() method returns some or all documents in the named collection.
db.name.modify()
The modify() method updates documents in the named collection.
db.name.remove()
The remove() method deletes one document or a list of documents from the named collection.
Create a Collection named ‘Zendcon’ and list all collections
26
mysql-js> db.createCollection("Zendcon")
<Collection:Zendcon>
mysql-js> db.getCollections()
[
<Collection:Zendcon>,
<Collection:countryinfo>
]
mysql-js>
mysql-js>db.countryinfo.add(
{
GNP: .6,
IndepYear: 1967,
Name: "Sealand",
_id: "SEA",
demographics: {
LifeExpectancy: 79,
Population: 27
},
geography: {
Continent: "Europe",
Region: "British Islands",
SurfaceArea: 193
},
government: {
GovernmentForm: "Monarchy",
HeadOfState: "Michael Bates"
}
}
)
27
use world_x
So lets use the
world_x sample
database and
add a new
record!
28
mysql-js> db.countryinfo.find("_id = 'USA'")
[
{
"GNP": 8510700,
"IndepYear": 1776,
"Name": "United States",
"_id": "USA",
"demographics": {
"LifeExpectancy": 77.0999984741211,
"Population": 278357000
},
"geography": {
"Continent": "North America",
"Region": "North America",
"SurfaceArea": 9363520
},
"government": {
"GovernmentForm": "Federal Republic",
"HeadOfState": "Donald J Clinton"
}
}
]
1 document in set (0.00 sec)
Use find to search
All the old qualifiers
are available for limit,
sort, etc.
29
Examples
mysql-js> db.countryinfo.find("GNP > 500000")
mysql-js> db.countryinfo.find("GNP > 500000 and demographics.Population
< 100000000")
db.countryinfo.find("Name = :country").bind("country", "Italy")
What if you want only certain tags?
mysql-js> db.countryinfo.find("GNP > 5000000").fields(["GNP", "Name"])
[
{
"GNP": 8510700,
"Name": "United States"
}
]
1 document in set (0.00 sec)
mysql-js>
30
More Examples
db.countryinfo.find().limit(5)
db.countryinfo.find().sort(["IndepYear desc"]).limit(8)
db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1)
db.countryinfo.modify("_id = 'SEA'").
set("demographics", {LifeExpectancy: 78, Population: 28})
db.countryinfo.modify("Name = 'Sealand'").unset("GNP")
31
db.countryinfo.modify().
set("Airports", [])
This will add a new array field named
Airports
In all records
32
db.countryinfo.modify("Name = 'France'").arrayAppend("$.Airports", "ORY")
db.countryinfo.find("Name = 'France'")
[
{
"Airports": [
"ORY"
],
"GNP": 1424285,
"IndepYear": 843,
"Name": "France",
"_id": "FRA",
33
Remove examples
db.countryinfo.remove("_id = 'SEA'")
db.countryinfo.remove().limit(1)
db.countryinfo.remove().sort(["Name desc"]).limit(1)
34
Indexes
db.countryinfo.createIndex("pop").
field("demographics.Population", "INTEGER",
false).execute()
35
Indexes can be added -- this index is on population value
under the demographics key, of type INTEGER, no NULLs
allowed.
There is also a dropIndex
You can also
access
relational
tables!!
36
37
Seeing tables
mysql-js> db.getTables()
[
<Table:city>,
<Table:country>,
<Table:countrylanguage>
]
mysql-js>
Basic table operations
db.name.insert()
The insert() method inserts one or more records into the named table.
db.name.select()
The select() method returns some or all records in the named table.
db.name.update()
The update() method updates records in the named table.
db.name.delete()
The delete() method deletes one or more records from the named table.
38
Insert Example
db.city.insert("ID", "Name", "CountryCode", "District",
"Info").
values(null, "Olympia", "USA", "Washington",
'{"Population": 5000}')
39
SELECT Examples
mysql-js> db.city.select().limit(1)
+----+-------+-------------+----------+-------------------------+
| ID | Name | CountryCode | District | Info |
+----+-------+-------------+----------+-------------------------+
| 1 | Kabul | AFG | Kabol | {"Population": 1780000} |
+----+-------+-------------+----------+-------------------------+
1 row in set (0.00 sec)
mysql-js> db.city.select(["Name", "CountryCode"])
db.city.select(["Name", "CountryCode"]).where("Name like 'Z%'")
40
UPdate & delete
db.city.update().set("Name", "Beijing").where("Name = 'Peking'")
db.city.delete().where("Name = 'Olympia'")
41
Supported languages
JavaScript, Python and SQL *
● More on the way 42
THANKS!Any questions?
You can find me at @stoker or david.stokes@oracle.com
slideshare.net/davidmstokes
Elephantanddolphin.blogger.com https://legacy.joind.in/talk/view/19538
43

More Related Content

What's hot

MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016
Wagner Bianchi
 
Schema replication using oracle golden gate 12c
Schema replication using oracle golden gate 12cSchema replication using oracle golden gate 12c
Schema replication using oracle golden gate 12c
uzzal basak
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practices
Dimas Prasetyo
 

What's hot (20)

MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바MySQL Advanced Administrator 2021 - 네오클로바
MySQL Advanced Administrator 2021 - 네오클로바
 
MySQL InnoDB Cluster 미리보기 (remote cluster test)
MySQL InnoDB Cluster 미리보기 (remote cluster test)MySQL InnoDB Cluster 미리보기 (remote cluster test)
MySQL InnoDB Cluster 미리보기 (remote cluster test)
 
Oss4b - pxc introduction
Oss4b   - pxc introductionOss4b   - pxc introduction
Oss4b - pxc introduction
 
Galera Replication Demystified: How Does It Work?
Galera Replication Demystified: How Does It Work?Galera Replication Demystified: How Does It Work?
Galera Replication Demystified: How Does It Work?
 
Introduction to ClustrixDB
Introduction to ClustrixDBIntroduction to ClustrixDB
Introduction to ClustrixDB
 
Ohio Linux Fest -- MySQL's NoSQL
Ohio Linux Fest -- MySQL's NoSQLOhio Linux Fest -- MySQL's NoSQL
Ohio Linux Fest -- MySQL's NoSQL
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
Replication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTIDReplication Troubleshooting in Classic VS GTID
Replication Troubleshooting in Classic VS GTID
 
Introduction to MariaDB MaxScale
Introduction to MariaDB MaxScaleIntroduction to MariaDB MaxScale
Introduction to MariaDB MaxScale
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationPercona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
 
Schema replication using oracle golden gate 12c
Schema replication using oracle golden gate 12cSchema replication using oracle golden gate 12c
Schema replication using oracle golden gate 12c
 
Multi thread slave_performance_on_opc
Multi thread slave_performance_on_opcMulti thread slave_performance_on_opc
Multi thread slave_performance_on_opc
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practices
 
Oracle Golden Gate
Oracle Golden GateOracle Golden Gate
Oracle Golden Gate
 
Easy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and TroubleshootingEasy MySQL Replication Setup and Troubleshooting
Easy MySQL Replication Setup and Troubleshooting
 
Managing MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona ToolkitManaging MariaDB Server operations with Percona Toolkit
Managing MariaDB Server operations with Percona Toolkit
 
監査ログをもっと身近に!〜統合監査のすすめ〜
監査ログをもっと身近に!〜統合監査のすすめ〜監査ログをもっと身近に!〜統合監査のすすめ〜
監査ログをもっと身近に!〜統合監査のすすめ〜
 

Similar to MySQL as a Document Store

[SSA] 03.newsql database (2014.02.05)
[SSA] 03.newsql database (2014.02.05)[SSA] 03.newsql database (2014.02.05)
[SSA] 03.newsql database (2014.02.05)
Steve Min
 

Similar to MySQL as a Document Store (20)

MySQL Document Store -- SCaLE 17x Presentation
MySQL Document Store -- SCaLE 17x PresentationMySQL Document Store -- SCaLE 17x Presentation
MySQL Document Store -- SCaLE 17x Presentation
 
Open Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational Database
 
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
MySQL Without the SQL - Oh My! -> MySQL Document Store -- Confoo.CA 2019
 
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
MySQL Without the SQL - Oh My! August 2nd presentation at Mid Atlantic Develo...
 
MySQL Without the SQL -- Oh My!
MySQL Without the SQL -- Oh My!MySQL Without the SQL -- Oh My!
MySQL Without the SQL -- Oh My!
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my!
 
Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational database
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
Discover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDiscover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQL
 
Discover The Power of NoSQL + MySQL with MySQL
Discover The Power of NoSQL + MySQL with MySQLDiscover The Power of NoSQL + MySQL with MySQL
Discover The Power of NoSQL + MySQL with MySQL
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the SQL -- Oh My!  Longhorn PHP ConferenceMySQL Without the SQL -- Oh My!  Longhorn PHP Conference
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
 
MySQL Without the MySQL -- Oh My!
MySQL Without the MySQL -- Oh My!MySQL Without the MySQL -- Oh My!
MySQL Without the MySQL -- Oh My!
 
Making MySQL Agile-ish
Making MySQL Agile-ishMaking MySQL Agile-ish
Making MySQL Agile-ish
 
20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
Python And The MySQL X DevAPI - PyCaribbean 2019
Python And The MySQL X DevAPI - PyCaribbean 2019Python And The MySQL X DevAPI - PyCaribbean 2019
Python And The MySQL X DevAPI - PyCaribbean 2019
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document Store
 
[SSA] 03.newsql database (2014.02.05)
[SSA] 03.newsql database (2014.02.05)[SSA] 03.newsql database (2014.02.05)
[SSA] 03.newsql database (2014.02.05)
 
MySQL without the SQL -- Cascadia PHP
MySQL without the SQL -- Cascadia PHPMySQL without the SQL -- Cascadia PHP
MySQL without the SQL -- Cascadia PHP
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
 

More from Dave Stokes

More from Dave Stokes (20)

Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
 
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre FeaturesLinuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
 
MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022
 
MySQL 8.0 Features -- Oracle CodeOne 2019, All Things Open 2019
MySQL 8.0 Features -- Oracle CodeOne 2019, All Things Open 2019MySQL 8.0 Features -- Oracle CodeOne 2019, All Things Open 2019
MySQL 8.0 Features -- Oracle CodeOne 2019, All Things Open 2019
 
Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
 
Develop PHP Applications with MySQL X DevAPI
Develop PHP Applications with MySQL X DevAPIDevelop PHP Applications with MySQL X DevAPI
Develop PHP Applications with MySQL X DevAPI
 
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL 8 Tips and Tricks from Symfony USA 2018, San FranciscoMySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
MySQL 8 Tips and Tricks from Symfony USA 2018, San Francisco
 
The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL Databases
 
MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Server Optimization Swanseacon 2018MySQL 8 Server Optimization Swanseacon 2018
MySQL 8 Server Optimization Swanseacon 2018
 
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
 
Presentation Skills for Open Source Folks
Presentation Skills for Open Source FolksPresentation Skills for Open Source Folks
Presentation Skills for Open Source Folks
 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
MySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreMySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document Store
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo Vancouver
 
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
 

Recently uploaded

Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
ChloeMeadows1
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
lolsDocherty
 

Recently uploaded (17)

Free scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirtsFree scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirts
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdf
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirts
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
 
I’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 ShirtI’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 Shirt
 
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdf
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirts
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of apps
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
GOOGLE Io 2024 At takes center stage.pdf
GOOGLE Io 2024 At takes center stage.pdfGOOGLE Io 2024 At takes center stage.pdf
GOOGLE Io 2024 At takes center stage.pdf
 

MySQL as a Document Store

  • 1. MySQl aS A dOCUMENTSTORE David.Stokes@Oracle.com @ Stoker slideshare.net/davidmstokes elelphantanddolphin.blogger.com
  • 2. "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." Safe Harbor 2
  • 3. Hello!I am Dave Stokes, MySQL Community Manager David.Stokes@Oracle.com @Stoker Slides at Slideshare.net/davidmstokes Blogs: Opensourcedba.wordpress.com elephantanddolphin.blogger.com 3
  • 4. 1. Json & json dATATYPE MySQL 5.7 4
  • 5. “JSON JavaScript Object Notation is a lightweight data-interchange format. It is built on two structures: A collection of name/vaule pairs and and ordered list of values.” 5
  • 6. MySQL JSON data type × Schemaless data × UTF8MB4 × It is just like a INT, or REAL, or TIMESTAMP. You can store an entire document in a column of a row of a table. You could store JSON in a CHAR/TEXT field but it is not sexy and you end up using REGEXP --- Ughhh! 6
  • 7. Big Very few developers are learning SQL (Structured Query Language), Relational Theory, Sets, data normalization or other database related subjects! 7
  • 8. SQL Data is normalized and formats are rigorously enforced. JOIN and logical operators allow complex queries. Costly to change schema. The big contest of 2014 In case you missed it NoSQL Schemaless, no need for relational overhead, changes as fast as the data, easy to implement. 8
  • 9. MySQl offers both SQL & NoSQL RDMS Good old relational database InnoDB/Memcached This plug-in allows direct access to InnoDB or NDB storage engine data using the memcached protocol, up to 9x faster JSON Data is stored in JSON format. No schema needed. Functions supplied for SQL based access & manipulation 9
  • 10. But what if you wanted a database but do not know sql? 10
  • 12. 12 JSON Documents and Collections A JSON document is a data structure composed of field/value pairs stored within a collection. The values of fields often contain other documents, arrays, and lists of documents.
  • 13. CRUD Operations Create, Read, Update and Delete (CRUD) operations are the four basic operations that can be performed on a database Collection or Table 13
  • 14. X Protocol The X Protocol supports both CRUD and SQL operations, authentication via SASL, allows streaming (pipelining) of commands and is extensible on the protocol and the message layer. 14
  • 15. Mysqlsh has three modes js -- JavaScript py -- python SQL -- SQL (like old Mysql shell) 15
  • 16. 1. MySQL 5.17.12 or later 2. Install X plugin a. mysql> INSTALL PLUGINmysqlx SONAME “mysqlx.so”; OR b. mysqlsh -u user -h localhost --classic --dba enableXProtocol 3. Install mysqlsh * 16 Installation needs ● Note: Installation of MySQL Shell using the MySQL APT repository is only supported on Ubuntu 14.04 LTS (“Trusty Tahr”) and Ubuntu 15.10 (“Wily Werewolf”).
  • 17. mysqlsh $ mysqlsh --uri dstokes:hidave@localhost world_x --node mysqlx: [Warning] Using a password on the command line interface can be insecure. Creating a Node Session to dstokes@localhost:33060/world_x Default schema `world_x` accessible through db. Welcome to MySQL Shell 1.0.5 Development Preview Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help', 'h' or '?' for help, type 'quit' or 'q' to exit. Currently in JavaScript mode. Use sql to switch to SQL mode and execute queries. mysql-js> 17
  • 18. MySQLSh shell Sessions MySQL Shell is a unified interface to operate MySQL Server through scripting languages such as JavaScript or Python. To maintain compatibility with previous versions, SQL can also be executed in certain modes. A connection to a MySQL server is required. In MySQL Shell these connections are handled by a Session object. 18 XSession: Use this session type for new application development. It offers the best integration with MySQL Server, and therefore, it is used by default. SQL execution is not supported Node Session: Use this session type for SQL execution on a MySQL Server with the X Protocol enabled. SQL execution is available Classic Session Use this session type to interact with MySQL Servers that do not have the X Protocol enabled ● --node creates a Node Session. ● --classic creates a Classic Session. ● --x creates an XSession.
  • 19. session mysql-js> session <NodeSession:dstokes@localhost:33060/world_x> mysql-js> The above tells us we are a JavaScript mode Account is dstokes@localhost on port 33060 The Database/schema is world_x 19
  • 20. session mysql-js> session <NodeSession:dstokes@localhost:33060/world_x> mysql-js> The above tells us we are a JavaScript mode Account is dstokes@localhost on port 33060 The Database/schema is world_x 20
  • 21. WHICH DATABASE AND WHICH COLLECTION mysql-js> db <Schema:world_x> mysql-js> db.getCollections() [ <Collection:countryinfo> ] mysql-js> 21 <-- The Database ← the table
  • 22. Batch Mode Example 22 echo "SELECT * FROM world_x.city LIMIT 2;" | mysqlsh --json=pretty --sqlc --uri user@host { "executionTime": "0.00 sec", "info": "", "rows": [ { "ID": 1, "Name": "Kabul", "CountryCode": "AFG", "District": "Kabol", "Info": "{"Population": 1780000}" }, { "ID": 2, "Name": "Qandahar", "CountryCode": "AFG", "District": "Qandahar", "Info": "{"Population": 237500}" } ], "warningCount": 0, "warnings": [], "hasData": true, "affectedRowCount": 0, "autoIncrementValue": 0 } This is a batch mode example where a query is sent to mysqlsh in sql mode and the output is produced in ‘pretty’ JSON format.
  • 23. Interactive help mysql-js> var mySchema = session.getSchema('Zendcon') The schema Zendcon does not exist, do you want to create it? [y/N]: y mysql-js> mySchema <Schema:Zendcon> mysql-js> Note the interactive error correction when a non existent schema is accessed. 23
  • 24. db 24 $ mysqlsh --uri dstokes:hidave@localhost world_x Default schema `world_x` accessible through db. ... mysql-js> db <Schema:world_x> mysql-js> db.getCollections() [ <Collection:countryinfo> ] mysql-js> db.countryinfo.find().limit(1) [ { "GNP": 828, "IndepYear": null, "Name": "Aruba" …. db is a global variable assigned to the current active schema that you specified on the command line.
  • 25. Basic Operators 25 db.name.add() The add() method inserts one document or a list of documents into the named collection. db.name.find() The find() method returns some or all documents in the named collection. db.name.modify() The modify() method updates documents in the named collection. db.name.remove() The remove() method deletes one document or a list of documents from the named collection.
  • 26. Create a Collection named ‘Zendcon’ and list all collections 26 mysql-js> db.createCollection("Zendcon") <Collection:Zendcon> mysql-js> db.getCollections() [ <Collection:Zendcon>, <Collection:countryinfo> ] mysql-js>
  • 27. mysql-js>db.countryinfo.add( { GNP: .6, IndepYear: 1967, Name: "Sealand", _id: "SEA", demographics: { LifeExpectancy: 79, Population: 27 }, geography: { Continent: "Europe", Region: "British Islands", SurfaceArea: 193 }, government: { GovernmentForm: "Monarchy", HeadOfState: "Michael Bates" } } ) 27 use world_x So lets use the world_x sample database and add a new record!
  • 28. 28 mysql-js> db.countryinfo.find("_id = 'USA'") [ { "GNP": 8510700, "IndepYear": 1776, "Name": "United States", "_id": "USA", "demographics": { "LifeExpectancy": 77.0999984741211, "Population": 278357000 }, "geography": { "Continent": "North America", "Region": "North America", "SurfaceArea": 9363520 }, "government": { "GovernmentForm": "Federal Republic", "HeadOfState": "Donald J Clinton" } } ] 1 document in set (0.00 sec) Use find to search All the old qualifiers are available for limit, sort, etc.
  • 29. 29 Examples mysql-js> db.countryinfo.find("GNP > 500000") mysql-js> db.countryinfo.find("GNP > 500000 and demographics.Population < 100000000") db.countryinfo.find("Name = :country").bind("country", "Italy")
  • 30. What if you want only certain tags? mysql-js> db.countryinfo.find("GNP > 5000000").fields(["GNP", "Name"]) [ { "GNP": 8510700, "Name": "United States" } ] 1 document in set (0.00 sec) mysql-js> 30
  • 31. More Examples db.countryinfo.find().limit(5) db.countryinfo.find().sort(["IndepYear desc"]).limit(8) db.countryinfo.find().sort(["IndepYear desc"]).limit(8).skip(1) db.countryinfo.modify("_id = 'SEA'"). set("demographics", {LifeExpectancy: 78, Population: 28}) db.countryinfo.modify("Name = 'Sealand'").unset("GNP") 31
  • 32. db.countryinfo.modify(). set("Airports", []) This will add a new array field named Airports In all records 32
  • 33. db.countryinfo.modify("Name = 'France'").arrayAppend("$.Airports", "ORY") db.countryinfo.find("Name = 'France'") [ { "Airports": [ "ORY" ], "GNP": 1424285, "IndepYear": 843, "Name": "France", "_id": "FRA", 33
  • 34. Remove examples db.countryinfo.remove("_id = 'SEA'") db.countryinfo.remove().limit(1) db.countryinfo.remove().sort(["Name desc"]).limit(1) 34
  • 35. Indexes db.countryinfo.createIndex("pop"). field("demographics.Population", "INTEGER", false).execute() 35 Indexes can be added -- this index is on population value under the demographics key, of type INTEGER, no NULLs allowed. There is also a dropIndex
  • 38. Basic table operations db.name.insert() The insert() method inserts one or more records into the named table. db.name.select() The select() method returns some or all records in the named table. db.name.update() The update() method updates records in the named table. db.name.delete() The delete() method deletes one or more records from the named table. 38
  • 39. Insert Example db.city.insert("ID", "Name", "CountryCode", "District", "Info"). values(null, "Olympia", "USA", "Washington", '{"Population": 5000}') 39
  • 40. SELECT Examples mysql-js> db.city.select().limit(1) +----+-------+-------------+----------+-------------------------+ | ID | Name | CountryCode | District | Info | +----+-------+-------------+----------+-------------------------+ | 1 | Kabul | AFG | Kabol | {"Population": 1780000} | +----+-------+-------------+----------+-------------------------+ 1 row in set (0.00 sec) mysql-js> db.city.select(["Name", "CountryCode"]) db.city.select(["Name", "CountryCode"]).where("Name like 'Z%'") 40
  • 41. UPdate & delete db.city.update().set("Name", "Beijing").where("Name = 'Peking'") db.city.delete().where("Name = 'Olympia'") 41
  • 42. Supported languages JavaScript, Python and SQL * ● More on the way 42
  • 43. THANKS!Any questions? You can find me at @stoker or david.stokes@oracle.com slideshare.net/davidmstokes Elephantanddolphin.blogger.com https://legacy.joind.in/talk/view/19538 43