MySQL Reference

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Welcome to the MySQL reference. MySQL is an open-source relational database server: it stores data in tables, is queried with SQL, and uses the InnoDB storage engine to provide ACID transactions, row-level locking, foreign keys and crash recovery. It powers a very large share of web applications and is available as a free Community Edition, a commercial Enterprise Edition and an Oracle-hosted cloud service. This section is a database-developer and operator reference for the MySQL server itself: how it is built, how to design tables and indexes for it, how to read query plans, how transactions and locks behave, how to run, back up and replicate it, and how to tune it. It is written for application developers who use MySQL every day and for the people who operate it.

MariaDB is a separate fork of MySQL whose features have diverged; it is not covered here, and statements, defaults and file layouts that are described for MySQL should not be assumed to hold for MariaDB.

If you are new to MySQL, read Getting Started first, then Architecture and Data Types & MySQL-specific SQL. Everything else builds on those. Engine-agnostic SQL (joins, subqueries, window functions) is on the sibling SQL Reference, which the MySQL pages link to instead of repeating.

Version baseline

The examples in this reference were run on MySQL 26.10.0 Community Server, obtained as the official mysql:latest Docker image (Linux, arm64). That is an Innovation release; MySQL publishes two release tracks, and the Docker image tags at the time of writing map as follows:

Track Version Docker tags

Innovation

26.10.0

latest, innovation, 26, 26.10

LTS

9.7.4

lts, 9, 9.7

LTS

8.4.13

8, 8.4

LTS releases only receive necessary fixes and are supported for five years of premier plus three of extended support; Innovation releases bring new features and are supported until the next Innovation release. Use an LTS for long-lived production systems. Everything described here is available on every maintained release unless a page says otherwise (for example window functions and CTEs need 8.0 or later), but a few defaults were observed on this server and are worth checking on your own version:

  • explain_format defaults to TREE, so a bare EXPLAIN prints a tree; use SET explain_format = TRADITIONAL for the table form.

  • The mysql client in the image has local commands such as \G and source disabled unless started with --commands.

  • The adaptive hash index is off by default, gtid_mode is ON, and the redo log capacity default is 100 MiB.

All results shown on the pages come from this server; they are trimmed where long, and the page says so. Numbers (timings, sizes, row estimates) will differ on your hardware, but the shape of the plans and behaviour should match. The manual is versioned, so use the matching one: 26.10, 8.4 LTS.

What’s covered

Foundations

  • Getting Started — what MySQL is, the Community, Enterprise and HeatWave editions, the LTS and Innovation release model, running a server in Docker, the mysql client, loading the shop sample database and a first session.

  • Architecture — connection threads, parser, optimizer, executor and pluggable storage engines; InnoDB tablespaces, the clustered index, pages, the buffer pool, change buffer, doublewrite buffer, undo and MVCC, the redo log, the binary log, two-phase commit and crash recovery.

Data and SQL

  • Data Types & MySQL-specific SQL — numeric, string, ENUM/SET and date/time types, character sets and collations, AUTO_INCREMENT, generated columns, upserts, INSERT IGNORE, REPLACE, multi-table UPDATE/DELETE, sql_mode, ONLY_FULL_GROUP_BY, and the INFORMATION_SCHEMA and SHOW commands.

  • JSON — the native JSON type, path expressions, JSON_TABLE, and multi-valued and functional indexes over JSON data.

Indexing and performance

  • Indexing — the clustered primary key, secondary, composite, covering, prefix, descending, functional and invisible indexes, FULLTEXT, spatial and hash indexes, statistics, maintenance and finding unused indexes, with EXPLAIN evidence on generated data.

  • Query Planning & EXPLAIN — reading EXPLAIN in table, tree and JSON form, EXPLAIN ANALYZE, nested-loop and hash joins, histograms, hints, optimizer_switch, the optimizer trace, subquery strategies, the slow query log and performance_schema digests.

  • Performance Tuning — the buffer pool, redo and flush settings, connection handling, a query-tuning workflow, partitioning and bulk loading.

Transactions

  • Transactions, Isolation & Locking — ACID and autocommit, the four isolation levels as InnoDB implements them, consistent reads, locking reads (FOR UPDATE, SKIP LOCKED), record, gap and next-key locks, deadlocks, lock waits, metadata locks, savepoints and implicit commits, with two-session demos.

Operations

  • Administration — users and roles, authentication plugins, privileges, configuration files and SET PERSIST, monitoring with performance_schema and sys, and routine maintenance.

  • Backup & Restore — logical backups with mysqldump and the dump utilities, physical backups, and point-in-time recovery from the binary log.

  • Replication & High Availability — binary-log replication, GTIDs, semi-synchronous replication, Group Replication, and an overview of InnoDB Cluster and MySQL Router.

Cheat sheet

  • Cheat Sheet — a single-page quick reference for the commands, statements and settings used throughout this section.

Deliberately out of scope. This section documents the MySQL server and its SQL, indexing, transaction and operations model. The following appear in many books on MySQL but are intentionally not covered here:

  • MariaDB — a separate fork with diverging features; see the MariaDB documentation.

  • NDB Cluster (ndbcluster) — a different, shared-nothing product; the Community server in the Docker image lists the engine as not enabled.

  • MySQL Enterprise-only features — Enterprise Audit, Firewall, Thread Pool, Transparent Data Encryption, Enterprise Backup and Oracle support tooling.

  • HeatWave — Oracle’s managed in-memory analytics and machine-learning service; mentioned only as an edition.

  • Cloud-managed services — Amazon RDS and Aurora, Google Cloud SQL, Azure Database for MySQL and the like. Their parameter groups and failover behave differently from a self-run server.

  • Installers per operating system — native packages, MSI, Homebrew and so on; the manual’s installation chapter is authoritative and this section runs the server in a container, see Docker.

  • MyISAM and other non-transactional engines — mentioned as history on the Architecture page only; new tables should use InnoDB.

  • Application object mapping — see Hibernate for JPA mapping onto MySQL.

Reading path

  1. Getting Started — run a server and load the sample data.

  2. Architecture — the layers and InnoDB’s structures; the later pages refer back to them.

  3. Data Types & MySQL-specific SQL — types, sql_mode and the statements that only MySQL has.

  4. Indexing — the biggest lever on performance.

  5. Query Planning & EXPLAIN — reading plans and finding slow statements.

  6. Transactions, Isolation & Locking — correctness under concurrency.

  7. JSON — document-style data inside a relational table.

  8. Administration — accounts, configuration and monitoring.

  9. Backup & Restore — before you need it.

  10. Replication & High Availability — copies and failover.

  11. Performance Tuning — the server-level knobs, once the queries and indexes are sound.

  12. Cheat Sheet — keep it open while you work.

A developer who only writes queries can stop after step 6; an operator should read steps 1, 2, 8, 9, 10 and 11 first.

Running example

All pages share one small online shop: four tables, customers, products, orders and order_items, holding 4 customers, 5 products, 8 orders and 11 order lines. The full script and the commands that load it are on Getting Started; the same data model is used by the MongoDB and PostgreSQL sections so the engines can be compared.

erDiagram CUSTOMERS ||--o{ ORDERS : places ORDERS ||--|{ ORDER_ITEMS : contains PRODUCTS ||--o{ ORDER_ITEMS : "appears in" CUSTOMERS { varchar id PK varchar name varchar email UK varchar city varchar tier datetime created_at } PRODUCTS { varchar sku PK varchar name varchar category decimal price int stock json tags json attrs } ORDERS { int id PK varchar customer_id FK varchar status datetime order_date } ORDER_ITEMS { int order_id PK varchar sku PK int qty decimal price }
  • customers — people who buy, with a tier of free, pro or enterprise (a CHECK constraint) and a unique e-mail.

  • products — items for sale, identified by sku, with a price, a stock count and two JSON columns, tags (an array) and attrs (an object), used on the JSON page.

  • orders — one per purchase, pointing at a customer, with a status of open, shipped or cancelled.

  • order_items — the lines of an order; its primary key is the pair (order_id, sku) and it carries the price charged at the time.

Pages add generated data (a recursive CTE creating hundreds of thousands of rows) only where an index or plan demonstration needs volume, in a separate lab database.

Bibliography