InnoDB redo, the binlog and the two-phase commit between them
innodb_flush_log_at_trx_commit, sync_binlog, binlog formats and what each crash point leaves behind. A free visual lesson with sample data.
More on MySQL and InnoDB
- InnoDB storage: clustered pages, change buffer, adaptive hash, doublewrite
- InnoDB read views, undo purge and the history list
- InnoDB Gap Locks and Next-Key Locks Explained
- A primary key is known before execution starts
- MySQL EXPLAIN Explained: const, ref, range, index, ALL
- MySQL settings that change query speed
- MySQL diagnosis: slow log, optimizer trace, performance schema
Keep learning
Overview
More redo means fewer forced checkpoints under bursts, and a longer crash recovery. innodb_log_file_size × innodb_log_files_in_group 48M × 2 (before 8.0.30) Memory for redo before it is written. Large transactions avoid early writes. 1: fsync per commit. 2: survives a mysqld crash, not an OS crash. 0: can lose ~1 s on any crash. How often settings 0 and 2 write and fsync. Binary logging is on by default since 8.0. yes (deprecated 8.0.34) MINIMAL logs only the key and changed columns: smaller, harder to audit. 1: fsync per commit group. N: per N groups. 0: the OS decides. Waits to form bigger groups: fewer fsyncs, longer commit latency. 2592000 (30 days) How long binlogs stay for replicas and point-in-time restores. yes (stepwise) ON tags every transaction with server_uuid:number so replicas can find their position. chapters · mysql and innodb InnoDB redo, the binlog and the two-phase commit between them MySQL writes two logs for every transaction: InnoDB's redo log for crash recovery and the server's binlog for replication. Two settings decide how much each can lose, and an internal two-phase commit keeps them in agreement.
1. Redo: LSN, log buffer, capacity
Every change appends redo records to the log buffer and advances the LSN. Since 8.0.30 the redo lives in 32 files under #innodb_redo, sized together by innodb_redo_log_capacity, which can be changed online. Before that it was innodb_log_file_size × innodb_log_files_in_group and a restart.
2. How much a crash can take: innodb_flush_log_at_trx_commit and sync_binlog
1 writes and fsyncs redo at every commit. 2 writes to the OS cache at commit and fsyncs once a second, so only an OS crash or power loss hurts. 0 writes once a second, so even a killed mysqld loses up to a second. Run 1 and 1 on a primary. Relaxing one of them is not only a durability trade: the two logs then lose different tails, and replicas drift from the primary. Relaxed values are fine on a replica you can rebuild, or during a bulk load.
3. Binlog formats: STATEMENT, ROW, MIXED
ROW, the default, logs before and after images of each changed row, so a replica applies exactly what the primary did. STATEMENT logs the SQL text and is unsafe for UUID(), LIMIT without ORDER BY and similar. MIXED logs statements and switches to rows when the server sees an unsafe one.
4. Internal two-phase commit and crash recovery
The binlog acts as the coordinator. InnoDB first prepares (durable in redo), then the binlog is written and synced, then InnoDB commits. On restart InnoDB lists its PREPARED transactions and looks up each Xid in the last binlog file: found means commit, missing means roll back.
Reference: log settings in MySQL 8.0
Variable, default, whether it can change at runtime, and the trade Default in 8.0 What it trades
Recap
The LSN is a byte position in the redo stream. Checkpoint age must stay under innodb_redo_log_capacity (8.0.30+). innodb_flush_log_at_trx_commit: 1 is durable, 2 survives a mysqld crash, 0 can lose about a second on any crash. Commit order: redo prepare → binlog write and fsync → redo commit. Recovery commits a prepared trx only if its Xid is in the binlog.
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.