Name

SET TRANSACTION

Synopsis

SET [GLOBAL|SESSION] TRANSACTION ISOLATION LEVEL
{READ UNCOMMITTED|READ COMMITTED|REPEATABLE READ|SERIALIZABLE}

Use this statement to set an isolation level for a transaction that’s about to be started, globally or only for the current session. This statement applies only to InnoDB and BDB tables.

The GLOBAL flag indicates that the isolation level should be applied to all transactions on the server that have not yet started. The SESSION flag limits the isolation level setting to just the current session.

The READ UNCOMMITTED isolation level allows SELECT statements to read tables without locking them and to read changes to rows that are not yet committed. The READ COMMITTED option is used to ensure consistent reading of data and to avoid any outside inserts while reading a table. The REPEATABLE READ option is used to ensure consistent SELECT statements during a transaction. The SERIALIZABLE option is used to ensure consistent reads; all simple SELECT statements are converted to SELECT...LOCK IN SHARE MODE statements.

Here is an example of how you can use this statement:

SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
START TRANSACTION;
...

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.