Isolation Levels
MySQL InnoDB supports four isolation levels controlling the visibility of uncommitted changes from other transactions.
MySQL InnoDB supports four isolation levels controlling the visibility of uncommitted changes from other transactions.
-- Set isolation level (session)
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
-- Levels (weakest → strongest):
-- READ UNCOMMITTED: sees dirty reads (uncommitted data)
-- READ COMMITTED: no dirty reads; non-repeatable reads possible
-- REPEATABLE READ: default; consistent snapshot within transaction
-- SERIALIZABLE: locks all reads; slowest, safest
SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ;
REPEATABLE READ is MySQL's default and prevents most anomalies without full SERIALIZABLE locking.