Quick revision
The short answer
The binary log records every change to the data so that replicas can repeat it and so that we can recover to a point in time after restoring a backup; it is a server-level log, separate from InnoDB's redo log. Statement-based format logs the SQL text, which is compact but unsafe for non-deterministic statements; row-based format, the default since 5.7, logs the changed rows, which is deterministic but larger for bulk changes; mixed format uses statements and switches to rows for unsafe ones. GTIDs give every transaction a global identifier, so a replica can find its position automatically after a failover.
What to remember
In this answer, we saw that the binlog is the server-level change log used for replication and point-in-time recovery, separate from InnoDB's redo log. Statement format logs SQL and is compact but unsafe for statements like UUID() or LIMIT without ORDER BY; row format logs row images, is deterministic and the default since 5.7, but is larger for bulk changes; mixed switches to rows for unsafe statements. GTIDs name every transaction globally, so replicas resume automatically after failover with SOURCE_AUTO_POSITION, and CDC tools need row format to see the data itself.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The binary log records every change to the data so that replicas can repeat it and so that we can recover to a point in time after restoring a backup; it is a server-level log, separate from InnoDB's redo log. Statement-based format logs the SQL text, which is compact but unsafe for non-deterministic statements; row-based format, the default since 5.7, logs the changed rows, which is deterministic but larger for bulk changes; mixed format uses statements and switches to rows for unsafe ones. GTIDs give every transaction a global identifier, so a replica can find its position automatically after a failover.
Why this question is asked
Most Java developers never configure the binary log, but it affects them more than they think: it is how read replicas get data, how change data capture tools like Debezium stream events, and how a database is recovered to the minute before a bad deploy. Interviewers ask about formats and GTIDs to check whether we understand replication well enough to reason about lag, failover and CDC. In this answer, we will recap what the binlog is and how it differs from the redo log, compare the three formats with examples, see what GTIDs add, and finish with why CDC tools need row-based logging.
1A Quick Recap of the Binary Log
The binary log, or binlog, is a sequence of files in which the MySQL server records every transaction that changes data, in commit order. Two jobs depend on it. Replicas connect to the source, copy its binlog events into their relay log, and apply them, which is how replication works. And after restoring last night's backup, we can replay the binlog with mysqlbinlog up to a chosen moment, which is point-in-time recovery.
It is easy to confuse with the InnoDB redo log, but they are different. The redo log belongs to the InnoDB engine, records physical page changes, is reused in a circle and exists for crash recovery. The binlog belongs to the server layer, records logical changes for any engine, is kept for days as files, and exists for replication and recovery. MySQL keeps the two consistent at commit with an internal two-phase commit.
2Statement-Based Logging
In statement format, the binlog contains the SQL text that changed the data, and the replica runs the same statement. An UPDATE that changes a million rows is one short event, which makes the log small. The problem is that the replica must reach exactly the same result, and some statements do not guarantee that.
Notice the difference between NOW() and UUID(). MySQL handles NOW() by logging the source's timestamp, so the replica uses the same value. UUID(), UPDATE or DELETE with LIMIT but no ORDER BY, and several other functions cannot be reproduced, so the replica may silently drift from the source.
3Row-Based and Mixed Logging
In row format, the binlog contains the rows themselves: for each changed row, the values before and after the change. The replica does not run any SQL; it applies the row changes. So the result is always identical, and the row images are what CDC tools need. Row format has been the default since MySQL 5.7.7.
The cost is size. The same million-row UPDATE now produces a million row images. binlog_row_image=MINIMAL logs only the columns needed to identify the row and the columns that changed, which shrinks the log a lot, at the cost of losing full before images. Mixed format logs statements by default and switches to row format automatically for statements MySQL knows are unsafe. In practice, row format is the standard today, and recent versions deprecate the binlog_format variable altogether with row logging as the long-term direction; check your version.
| Format | Logs | Strength | Weakness |
|---|---|---|---|
| STATEMENT | the SQL text | small for bulk changes | unsafe statements can diverge |
| ROW (default) | before and after row images | deterministic; used by CDC | large for bulk changes |
| MIXED | statements, rows when unsafe | smaller than ROW | two behaviours to reason about |
4What GTIDs Add
Without GTIDs, a replica remembers its position as a binlog file name and offset on its source, such as binlog.000412 at position 88231. After a failover, that position means nothing on the new source, whose files are numbered differently, and finding the right starting point by hand is slow and error-prone.
A global transaction identifier gives every transaction a unique name of the form source_uuid:sequence_number, which stays the same on every server it reaches. Each server records the set of GTIDs it has applied in gtid_executed. So after a failover, a replica just tells the new source which transactions it already has, and the source sends the rest. GTIDs also prevent applying the same transaction twice.
5 messages in order. Play them, or step through them one at a time.
SOURCE_AUTO_POSITION is the current name; older versions used MASTER_AUTO_POSITION with CHANGE MASTER TO. enforce_gtid_consistency rejects the few statements that cannot be logged as a single safe transaction, such as CREATE TABLE ... SELECT in older versions.
5Follow-up questions
Why do CDC tools like Debezium require row-based binlog?
Because they turn each change into an event with the row's values, and only row format contains those values. A statement like UPDATE ... WHERE created_at < ... says nothing about which rows changed or what they became, and working it out would require running the statement against the same data. Debezium also asks for binlog_row_image=FULL, so every event carries the complete before and after row.
Is the binlog needed if we have no replicas?
Usually yes, because point-in-time recovery depends on it. A nightly backup alone can only take us back to last night; the backup plus the binlog can take us to one second before the accidental DELETE. Binlog files are kept for binlog_expire_logs_seconds, 30 days by default.
Does row format make replication slower?
It can for bulk changes, because the replica applies many row events and tables without a primary key force it to search for each row. For ordinary OLTP traffic it is often faster, since the replica does not re-run expensive queries.
6Conclusion
In this answer, we saw that the binlog is the server-level change log used for replication and point-in-time recovery, separate from InnoDB's redo log. Statement format logs SQL and is compact but unsafe for statements like UUID() or LIMIT without ORDER BY; row format logs row images, is deterministic and the default since 5.7, but is larger for bulk changes; mixed switches to rows for unsafe statements. GTIDs name every transaction globally, so replicas resume automatically after failover with SOURCE_AUTO_POSITION, and CDC tools need row format to see the data itself.
Open with
The binary log is the server-level record of every data change, in commit order. Replicas copy and apply it, and after restoring a backup we replay it for point-in-time recovery.
Then, if they want more
It is separate from the InnoDB redo log, which is an engine-level, circular log of page changes for crash recovery; the two are tied together at commit by an internal two-phase commit. There are three formats.
Statement-based logs the SQL text, which is small for bulk updates, but non-deterministic statements are unsafe: NOW is fine because the timestamp is logged, but UUID, or a DELETE with LIMIT and no ORDER BY, can give different results on the replica.
Row-based logs the before and after images of every changed row, so it is deterministic, and it has been the default since 5.7, but a bulk update can produce a huge log; binlog_row_image MINIMAL reduces that. Mixed logs statements and switches to rows when a statement is unsafe.
GTIDs give each transaction a global id, server uuid plus a sequence number, and every server tracks which ones it has executed. So after a failover a replica uses SOURCE_AUTO_POSITION to tell the new source what it already has, instead of anyone working out file names and offsets.
CDC tools like Debezium need row format because they publish the actual row values.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- MySQL 5.7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the MySQL binary log used for? Compare statement-based, row-based and mixed...": https://scrivio-interview-library.netlify.app/databases/mysql/51784d9156/