Skip to content

Commit b6cd1b9

Browse files
committed
Initial additions
1 parent 258950c commit b6cd1b9

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# MariaDB JSON Quickstart
2+
3+
This repository uses the [official MariaDB Docker image](https://hub.docker.com/_/mariadb) to demonstrate how to manage semi-structured, via [JavaScript Objection Notation (JSON)](https://www.json.org/json-en.html), within a [MariaDB](https://mariadb.com) database.
4+
5+
<p align="center" spacing="10">
6+
<kbd>
7+
<img src="media/demo.gif" />
8+
</kbd>
9+
</p>
10+
11+
This README will walk you through the steps for getting a MariaDB database up and running, using a [Docker container](https://www.docker.com/resources/what-container), and automatically create a [database, table and pre-load the table with data](database/places.sql).
12+
13+
## Requirements
14+
15+
This sample requires that you have the following installed:
16+
17+
* [Docker](https://docs.docker.com/get-docker/)
18+
19+
## Setup Instructions
20+
21+
The following provides for getting started using JSON with MariaDB (via a MariaDB database instance within a Docker container).
22+
23+
1. Pull down this respository by either downloading it directly or use [git](git-scm.org) (through CLI or a client) to retrieve the code using `git clone`:
24+
25+
```
26+
$ git clone https://github.com/mariadb-developers/mariadb-json-quickstart.git
27+
```
28+
29+
2. Navigate to the root of this sample, and execute the [docker-compose up](https://docs.docker.com/compose/reference/up/) command to run [docker-compose.yml](docker-compose.yml):
30+
31+
```bash
32+
$ docker-compose up -d
33+
```
34+
35+
**Note:** The `docker-compose up` command will use the [docker-compose.yml](docker-compose.yml) file to spin up a new Docker container (using the official MariaDB Docker image) and [execute SQL](data/places.sql) to create a new database (`places`), tables (`locations`), and load it with sample data.
36+
37+
38+
3. Use the `docker` CLI command to use the `mariadb` command-line client, included in the Docker container, to connect and query your MariaDB database.
39+
40+
```bash
41+
$ docker exec -it mdb_json mariadb -u root -pPassword123!
42+
```
43+
44+
which will load the MariaDB command-line client, which will enable to start executing SQL using MariaDB JSON functionality.
45+
46+
<p align="center" spacing="10">
47+
<kbd>
48+
<img src="media/client.png" />
49+
</kbd>
50+
</p>
51+
52+
## Helpful Resources
53+
54+
* [Official MariaDB JSON documentation](https://mariadb.com/docs/appdev/json/#json)
55+
* [Getting Started with JSON and MariaDB](https://medium.com/mariadb/hybrid-data-models-how-to-have-your-json-cake-and-eat-mariadb-too-ee809604d1f1) (blog post)
56+
57+
## Support and Contribution <a name="support-contribution"></a>
58+
59+
Please feel free to submit PR's, issues or requests to this project project directly.
60+
61+
If you have any other questions, comments, or looking for more information on MariaDB please check out:
62+
63+
* [MariaDB Developer Hub](https://mariadb.com/developers)
64+
* [MariaDB Community Slack](https://r.mariadb.com/join-community-slack)
65+
66+
Or reach out to us diretly via:
67+
68+
69+
* [MariaDB Twitter](https://twitter.com/mariadb)
70+
71+
## License <a name="license"></a>
72+
[![License](https://img.shields.io/badge/License-MIT-blue.svg?style=plastic)](https://opensource.org/licenses/MIT)

data/places.sql

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
DROP DATABASE IF EXISTS `places`;
2+
3+
CREATE DATABASE `places`;
4+
5+
USE `places`;
6+
7+
CREATE TABLE `locations` (
8+
`id` INT unsigned NOT NULL AUTO_INCREMENT,
9+
`name` VARCHAR(100) NOT NULL,
10+
`description` VARCHAR(250),
11+
`type` char(1) NOT NULL DEFAULT '',
12+
`latitude` DECIMAL(9,6) NOT NULL,
13+
`longitude` DECIMAL(9,6) NOT NULL,
14+
`attr` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`attr`)),
15+
PRIMARY KEY (`id`)
16+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
17+
18+
/* Load data */
19+
20+
/* Locations */
21+
INSERT INTO `locations` (`name`, `description`, `type`, `latitude`, `longitude`, `attr`)
22+
VALUES
23+
('The Scout', 'A sports bar in South Loop', 'R', 41.865624, -87.625283, X'7B2264657461696C73223A207B22666F6F6454797065223A20224D65786963616E222C20226D656E75223A2022687474703A2F2F74686573636F75746368696361676F2E636F6D227D2C20226661766F7269746573223A205B7B226465736372697074696F6E223A202257726170222C20227072696365223A202224392E3939227D5D7D'),
24+
('Chicago Cut Steakhouse', 'A steakhoue in River North', 'R', 41.887884, -87.633075, X'7B2264657461696C73223A207B2022666F6F6454797065223A22537465616B686F757365222C20226D656E75223A22687474703A2F2F74686573636F75746368696361676F2E636F6D227D2C20226661766F7269746573223A205B5D7D'),
25+
('The Art Institute of Chicago', 'Renowned art museum holding nearly 300,000 works from all over the world, spanning many centuries.', 'A', 41.879585, -87.623713, X'7B2263617465676F7279223A20224D757365756D222C20226C617374566973697444617465223A202231312F352F32303139227D'),
26+
('United Center', 'NBA stadium - home of the Bulls and Blackhawks', 'S', 41.880691, -87.674176, X'7B2264657461696C73223A207B22796561724F70656E6564223A20313939342C20226361706163697479223A2032333530307D2C20226576656E7473223A205B7B2264617465223A202231302F31382F32303139222C20226465736372697074696F6E223A202242756C6C732076732043656C74696373227D2C207B2264617465223A202231302F32312F32303139222C20226465736372697074696F6E223A202242756C6C73207673204C616B657273227D2C207B2264617465223A202231312F352F32303139222C20226465736372697074696F6E223A202242756C6C73207673204275636B73227D2C207B2264617465223A202231312F352F32303139222C20226465736372697074696F6E223A2022426C61636B6861776B7320767320426C756573227D5D7D'),
27+
('Guaranteed Rate Field', 'MLB stadium - home of the White Sox', 'S', 41.829902, -87.633752, X'7B2264657461696C73223A207B22796561724F70656E6564223A20313939312C20226361706163697479223A2034303631357D2C20226576656E7473223A205B7B2264617465223A2022352F312F32303230222C20226465736372697074696F6E223A20225768697465736F7820767320526F79616C73227D5D7D'),
28+
('Willis Tower', NULL, 'A', 41.878876, -87.635915, X'7B2263617465676F7279223A20224C616E646D61726B222C20226C617374566973697444617465223A202231312F31312F32303139227D'),
29+
('Soldier Field', 'NFL stadium - home of the Bears', 'S', 41.862313, -87.616688, X'7B2264657461696C73223A207B2022796561724F70656E6564223A20313932322C20226361706163697479223A2036313530307D2C20226576656E7473223A205B7B2264617465223A202231302F32302F32303139222C20226465736372697074696F6E223A20224265617273207673205361696E7473227D2C207B2264617465223A202231302F32372F32303139222C20226465736372697074696F6E223A20224265617273207673204368617267657273227D5D7D'),
30+
('Cloud Gate', NULL, 'A', 41.882661, -87.623304, X'7B2263617465676F7279223A20224C616E646D61726B222C20226C617374566973697444617465223A202231312F352F32303139227D'),
31+
('Navy Pier', 'An outdoor shopping center', 'A', 41.891863, -87.605094, X'7B2263617465676F7279223A202253686F7070696E672043656E746572222C20226C617374566973697444617465223A202231312F382F32303139227D'),
32+
('The Publican', NULL, 'R', 41.886629, -87.648851, X'7B2264657461696C73223A207B22666F6F6454797065223A2022416D65726963616E222C20226D656E75223A2022687474703A2F2F7777772E7468657075626C6963616E72657374617572616E742E636F6D2F227D2C20226661766F7269746573223A205B7B226465736372697074696F6E223A2022427572676572222C20227072696365223A20222431322E3939227D2C207B226465736372697074696F6E223A202257696E6773222C20227072696365223A202224392E3939227D2C207B226465736372697074696F6E223A202253616C6164222C20227072696365223A202224382E3939227D2C207B226465736372697074696F6E223A202257726170222C20227072696365223A20222431342E3939227D2C207B226465736372697074696F6E223A2022537465616B222C20227072696365223A20222432392E3030227D5D7D'),
33+
('Sunda', 'An Asian restaurant in River North', 'R', 41.890952, -87.631743, X'7B2264657461696C73223A207B22666F6F6454797065223A2022417369616E222C20226D656E75223A2022687474703A2F2F73756E64616E6577617369616E2E636F6D227D2C20226661766F7269746573223A205B5D7D'),
34+
('Chicago French Market', NULL, 'A', 41.884137, -87.640973, X'7B2263617465676F7279223A202253686F7070696E67222C20226C617374566973697444617465223A202231302F33312F32303139227D'),
35+
('The Chicago Theatre', NULL, 'A', 41.885264, -87.627647, X'7B2263617465676F7279223A202254686561746572222C20226C617374566973697444617465223A202231312F342F32303139227D'),
36+
('Giordanos', NULL, 'R', 41.876388, -87.647639, X'7B2264657461696C73223A207B22666F6F6454797065223A202250697A7A61222C20226D656E75223A2022687474703A2F2F7777772E67696F7264616E6F732E636F6D2F6D656E75227D2C20226661766F7269746573223A205B7B226465736372697074696F6E223A20224368696361676F20436C6173736963222C20227072696365223A20222432342E3939227D2C207B226465736372697074696F6E223A202253616C6164222C20227072696365223A202224392E3939227D5D7D');

docker-compose.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3"
2+
services:
3+
mariadb:
4+
image: mariadb:latest
5+
container_name: mdb_json
6+
ports:
7+
- 3306:3306
8+
volumes:
9+
- ./data:/docker-entrypoint-initdb.d
10+
environment:
11+
MARIADB_ROOT_PASSWORD: 'Password123!'

media/client.png

241 KB
Loading

media/demo.gif

494 KB
Loading

0 commit comments

Comments
 (0)