Databases 8 min read

Using MySQL X API as a NoSQL Alternative: Configuration, CRUD Examples, and Advanced Operations

This article explains how MySQL X API (available since MySQL 5.7) can replace NoSQL databases by enabling the X protocol, showing configuration steps, equivalent insert examples, and detailed CRUD, indexing, and transaction operations with code snippets.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Using MySQL X API as a NoSQL Alternative: Configuration, CRUD Examples, and Advanced Operations

Background: a user asks whether MySQL can handle flexible‑schema data without deploying a separate NoSQL system.

Answer: MySQL X API, introduced in MySQL 5.7, can serve as a NoSQL‑style interface. To enable it, add the X port to the MySQL configuration.

#my.cnf
[mysqld]
port=3305               # traditional MySQL port
mysqlx_port=33050          # MySQL X protocol port

Example – inserting ten documents into MongoDB and performing the same operation with MySQL X API.

# MongoDB shell
use ytt
var c1 = []
for (var i = 0; i < 10; i++) { c1.push({x:i, y:i*2, z:i+100}); }
db.f1.insert(c1);
print(db.f1.count()); // 10
# MySQL Shell (X protocol)
db.createCollection('f1');
var c1 = []
for (var i = 0; i < 10; i++) { c1.push({x:i, y:i*2, z:i+100}); }
db.f1.add(c1);
print(db.f1.count()); // 10

Further operations such as update, delete, array manipulation, indexing and transactions are demonstrated.

# Update a record where x=1
db.f1.modify('x=1').set('x','mysql');

# Delete all records
db.f1.remove('true');

# Append an array to field x
db.f1.modify('true').arrayAppend('$.x', c1);

# Create an index on field x
db.f1.createIndex('idx_x', {fields:[{'field':'$.x','type':'int'}]});

# Transaction example
session.startTransaction();
db.f1.remove('x=1');
session.rollback();

The examples demonstrate that MySQL X API provides full CRUD, indexing, and transaction capabilities, making it a practical substitute for MongoDB or other NoSQL solutions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

indexingdatabasemysqlCRUDTransactionsNoSQLX API
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.