// mysql · sql behavior

transaction_isolation

Default transaction isolation level.

預設
REPEATABLE-READ
Range
READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE
Restart needed
否
Default checked on
MySQL 8.4 LTS

其作用

REPEATABLE READ gives each transaction a consistent snapshot and uses gap locks on locking reads; READ COMMITTED takes a fresh snapshot per statement and uses fewer gap locks.

預設值

REPEATABLE-READ. REPEATABLE-READ (MySQL 8.4).

Check the current value

SHOW GLOBAL VARIABLES LIKE 'transaction_isolation';

SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME
FROM performance_schema.variables_info
WHERE VARIABLE_NAME = 'transaction_isolation';

Change it

SET SESSION transaction_isolation = 'READ-COMMITTED';   -- this connection
SET GLOBAL transaction_isolation = 'READ-COMMITTED';    -- new connections, until restart
SET PERSIST transaction_isolation = 'READ-COMMITTED';   -- new connections, and after restarts

No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.

When to change it

READ COMMITTED reduces gap-lock deadlocks in high-concurrency write workloads and matches what PostgreSQL, SQL Server and Oracle default to.

What can go wrong

Repeated reads inside one transaction can now return different rows. With READ COMMITTED, InnoDB refuses statement-based binary logging, so binlog_format must stay ROW (the default) or MIXED.

Questions about transaction_isolation

What is the default value of transaction_isolation in MySQL?

REPEATABLE-READ. REPEATABLE-READ (MySQL 8.4).

Does changing transaction_isolation require a restart?

No. No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.

When should I change transaction_isolation?

READ COMMITTED reduces gap-lock deadlocks in high-concurrency write workloads and matches what PostgreSQL, SQL Server and Oracle default to.

Back to all MySQL settings, or check the MySQL manual for every option.

// one client for every engine

Check transaction_isolation on your own server

SQLly runs the query above against MySQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.