Databases 10 min read

Using MySQL Shell to Operate Relational Tables: Examples with MySQL, MySQL X, and SHELL Components

This tutorial demonstrates how to use MySQL Shell's three components—MySQL, MySQL X, and SHELL—to connect to a sample WORLD database, perform CRUD operations, execute transactions, and run advanced queries with code examples for each component.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Using MySQL Shell to Operate Relational Tables: Examples with MySQL, MySQL X, and SHELL Components

The article introduces MySQL Shell as a versatile tool that can manipulate both document and relational data, focusing on three components: the classic MySQL component, the MySQL X component (based on the X Dev protocol), and the SHELL component that can switch between the two.

MySQL component : Shows how to connect using mysql.get_session or a dictionary, then run SQL statements with run_sql to query, insert, update, delete, start transactions, and close the connection. Sample code snippets illustrate each operation on the city table of the SAMPLE DATABASE WORLD.

MySQL X component : Demonstrates connecting via the X protocol, executing plain SQL, using the SQLRESULT class for fetching rows, the SqlExecute class for prepared‑statement style queries with bound variables, and the Table class (including its sub‑classes TableSelect, TableInsert, TableUpdate, TableDelete) for object‑oriented DML operations. Examples cover selecting cities with population < 800, inserting single and multiple rows, updating, and deleting records.

SHELL component : Explains that the SHELL component can freely switch between MySQL and MySQL X sessions and provides a default db object representing the current schema. It shows how to obtain a Table object via db.get_table("city") and perform the same queries as with MySQL X.

The article concludes that using the SHELL component is the most flexible way to operate relational tables in MySQL Shell and provides several recommended reading links for further exploration.

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.

SQLdatabasemysqlShellTutorialdata manipulationX Protocol
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.