MySQL Enterprise Edition includes powerful audit filtering capabilities, but writing audit filter JSON by hand can be tedious and error-prone. The JSON model is flexible, which is exactly what makes it useful, but it also means that a small typo, a missing event class, or an incorrectly assigned user can change what does or does […]
The latest from the MySQL community
Ideas, releases, practical guides, and perspectives from the people building with MySQL.
This post covers a hands-on walkthrough of MySQL 8.0's JSON functions. JSON support has been in MySQL since 5.7, but 8.0 added a meaningful set of improvements — better indexing strategies, new functions, and multi-valued indexes — that make working with JSON data considerably more practical. The following documents several of the most commonly needed patterns, including EXPLAIN output and performance observations worth knowing about.
This isn't a "JSON vs. relational" debate post. If you're storing JSON in MySQL, you probably already have your reasons. The goal here is to make sure you're using the available tooling effectively.
Environment
mysql> SELECT @@version, @@version_comment\G
*************************** 1. row ***************************
@@version: 8.0.36
@@version_comment: MySQL Community Server - GPL
Testing was done on a VM with 8GB RAM and …
[Read more]We recently saw that we can benefit from using JSON documents with MySQL HeatWave cluster in OCI (HeatWave accelerator for MySQL Database Service).
However sometimes the data can’t be loaded to HeatWave Cluster or the query cannot use it.
And this is not always easy to understand why. Let’s get familiar on how to find the info.
Data not loaded in HW Cluster
Let’s see an example with this table (collection):
SQL > show create table listingsAndReviews\G
*************************** 1. row ***************************
Table: listingsAndReviews
Create Table: CREATE TABLE `listingsAndReviews` (
`doc` json DEFAULT NULL,
`_id` char(28) GENERATED ALWAYS AS
(json_unquote(json_extract(`doc`,_utf8mb4'$._id'))) STORED NOT NULL,
`_json_schema` json GENERATED ALWAYS AS
(_utf8mb4'{"type":"object"}') VIRTUAL,
PRIMARY KEY (`_id`),
CONSTRAINT `$val_strict_B70EB65BDDBAB20B0EE5BB7532C9060C422A06F8` …[Read more]
Since the release of MySQL 8.0, the MySQL X Dev API has provided users with the convenient ability to utilize MySQL without the need to write a single line of SQL!
MySQL X Dev API brings the support for CRUD operations on JSON documents that are stored in MySQL. MySQL Document Store is ACID compliant and is compatible with everything MySQL like replication, InnoDB Cluster, …
The MySQL X Dev API is available using the MySQL X Protocol, listening by default on port 33060.
If you are interested in learning more about MySQL Document Store, please refer to the these presentations [1], [2], [ …
[Read more]If you read - Using the JSON data type with MySQL 8 - Part I, you will see that inserting data into MySQL of JSON type is a very common and effective practice. Now we’ll see how to do it with a Python project, using SQLAlchemy and Docker Compose, which further automates this example. You can run this example using a single command: docker-compose up
Before getting down to work, we will review some important concepts:
- Percona Server for MySQL is an open source, drop-in replacement for MySQL Community that provides better performance, more scalability, and enhanced security features.
- SQLAlchemy is a library that allows us to communicate between Python …
If you are a mobile app, frontend, backend, or game developer, you use data types such as string, numeric, or DateTime. You also know that since the advent of non-relational databases (NoSQL) such as MongoDB, which, by not being tied to a traditional SQL schema, do reading and writing on databases much faster. But MySQL showed that storing the JSON (JavaScript Object Notation) data type could also improve the speed of reading and writing relational databases.
This post will explore the JSON Data type in Percona Server for MySQL.
One of the key features of Percona Server is support for JSON data type, which allows for the storage of JSON documents within MySQL. It allows for more flexible and efficient storage of semi-structured data (which is more …
[Read more]One of my students asked how you could get JSON data out in tabular format. I said they should look at Øystein Grøvlen’s JSON_TABLE – Best of Both Worlds blog post from 2018. Unfortunately, the student wanted another example with the Video Store model that we use in class.
For clarity, all path definitions start with a $ followed by other selectors:
- A period followed by a name, such as $.website
- [N] where N is the position in a zero-indexed array
- The .[*] wildcard evaluates all members of an object
- The [*] wildcard evaluates all members of an array
- The prefix and suffix wildcard, **, evaluates to all paths that begin with the named prefix and end with the named suffix
So, here’s a quick supplement to what’s already there. It assumes you created an …
[Read more]Yesterday, I wrote a blog post that showed you how to write a query returning a JSON structure for a 1:many relationship. The relationship was between the member and contact table. It returns one account_number from the member table and a list of first_name and last_name columns from the contact table in a JSON structure.
One of my students asked why I choose to strip the backslashes with Python, and my reply was the SQL was already complex for most blog readers. The student asked but how would you do it in SQL. OK, that’s a fair question for two reasons. First, you don’t need to do in your local programs because it’ll run faster on the server. Second, if you strip the backslashes you can insert it into a standard JSON column. This blog post will show you how to do both.
You would use three REGEXP_REPLACE function calls, like:
…[Read more]Are they really tricks or simply basic techniques combined to create a solution. Before writing these mechanics for using native MySQL to create a compound JSON object, let me point out that the easiest way to get one is to use the MySQL Node.js library, as shown recently in my “Is SQL Programming” blog post.
Moving data from a relational model output to a JSON structure isn’t as simple as a delimited list of columns in a SQL query. Let’s look at it in stages based on the MySQL Server 12.18.2 Functions that create JSON values.
Here’s how you return single row as a JSON object, which is quite straightforward:
SELECT JSON_OBJECT('first_name',c.first_name,'last_name',c.last_name) AS json_result
FROM contact c
WHERE …[Read more]
Let’s start with some info about how MySQL Document Store handles JSON documents.
Document Store and CRUD
We know that MySQL 8.0 Document Store handles JSON documents with CRUD operations. We can add, delete and modify those documents very easily:
JS >db.mycollection.find()
{
"_id": "0000624d3e890000000000000001",
"name": "my_iot1",
"type": "sensor",
"capabilities": "{'temperature':'true','humidity':'true'}"
}
{
"_id": "0000624d3e890000000000000002",
"name": "my_iot2",
"type": "sensor",
"capabilities": "{'temperature':'true'}"
}
2 documents in set (0.0007 sec)
To modify a document, the modify method can be used in different
ways:
As illustrate above, we have:
-
set() - …