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 |
|
LTS |
9.7.4 |
|
LTS |
8.4.13 |
|
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_formatdefaults toTREE, so a bareEXPLAINprints a tree; useSET explain_format = TRADITIONALfor the table form. -
The
mysqlclient in the image has local commands such as\Gandsourcedisabled unless started with--commands. -
The adaptive hash index is off by default,
gtid_modeisON, and the redo log capacity default is 100 MiB.
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
mysqlclient, 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/SETand date/time types, character sets and collations,AUTO_INCREMENT, generated columns, upserts,INSERT IGNORE,REPLACE, multi-tableUPDATE/DELETE,sql_mode,ONLY_FULL_GROUP_BY, and theINFORMATION_SCHEMAandSHOWcommands. -
JSON — the native
JSONtype, 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, withEXPLAINevidence on generated data. -
Query Planning & EXPLAIN — reading
EXPLAINin 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 andperformance_schemadigests. -
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 withperformance_schemaandsys, and routine maintenance. -
Backup & Restore — logical backups with
mysqldumpand 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
-
Getting Started — run a server and load the sample data.
-
Architecture — the layers and InnoDB’s structures; the later pages refer back to them.
-
Data Types & MySQL-specific SQL — types,
sql_modeand the statements that only MySQL has. -
Indexing — the biggest lever on performance.
-
Query Planning & EXPLAIN — reading plans and finding slow statements.
-
Transactions, Isolation & Locking — correctness under concurrency.
-
JSON — document-style data inside a relational table.
-
Administration — accounts, configuration and monitoring.
-
Backup & Restore — before you need it.
-
Replication & High Availability — copies and failover.
-
Performance Tuning — the server-level knobs, once the queries and indexes are sound.
-
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.
-
customers— people who buy, with atieroffree,proorenterprise(aCHECKconstraint) and a unique e-mail. -
products— items for sale, identified bysku, with aprice, astockcount and twoJSONcolumns,tags(an array) andattrs(an object), used on the JSON page. -
orders— one per purchase, pointing at a customer, with astatusofopen,shippedorcancelled. -
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.
Related material on this site
-
SQL Reference — standard SQL for every relational engine.
-
PostgreSQL Reference — the sibling reference for PostgreSQL, using the same shop data.
-
MongoDB Reference — the document-database counterpart.
-
Diagnosing Slow Queries — an engine-neutral method for performance problems.
-
Pagination Strategies —
OFFSETversus keyset paging and their costs. -
Choosing the Right Database — when a relational database is the right choice.
-
Evolving the Database Model — migration tools for changing a schema safely.
-
Database Migration — moving data between databases, including with change data capture from MySQL.
-
Hibernate — mapping entities to MySQL tables from Java.
-
Docker — containers and volumes, which every example here relies on.
Bibliography
-
MySQL Reference Manual — the source every page is written and verified against; see in particular the release model, The InnoDB Storage Engine, the InnoDB locking and transaction model, Data Types, SQL Statements, Optimization including EXPLAIN Output Format, The JSON Data Type, Backup and Recovery, Replication, Security, the Performance Schema and the sys Schema.
-
MySQL 8.4 Reference Manual — the LTS manual, including the release model page that defines the LTS and Innovation tracks.
-
MySQL 26.10 release notes and the upgrade guide — what changed between releases.
-
MySQL Shell documentation — the AdminAPI, dump and load utilities used on the operations pages.
-
The official
mysqlDocker image — tags, environment variables and initialisation hooks used in the examples. -
MySQL Server internals documentation — source-level documentation for the curious.
-
Schwartz, Baron; Zaitsev, Peter; Tkachenko, Vadim. High Performance MySQL: Optimization, Backups, and Replication, 3rd ed. O’Reilly Media, 2012; see oreilly.com. Consulted for topic coverage. It targets MySQL 5.5, so current behaviour here was verified against the running server rather than taken from the book.