The user can use the SET TRANSACTION statement to change the isolation level of a single session or all new incoming connections. Its syntax is as follows:
SET [SESSION | GLOBAL] TRANSACTION Isolation Level {READ UNCOMMITTED | READ COMMITTED | Repeatable READ | SERIALIZABLE}
Note: The default behavior (without session and global) is to set the isolation level for the next (not started) transaction. If you use the Global keyword, the statement sets the default transaction level globally for all new connections created from that point, except for connections that do not exist. You need super privilege to do this. Use the session keyword to set the default transaction level for future transactions performed on the current connection. Any client can freely change the session isolation level (even in the middle of a transaction) or set the isolation level for the next transaction.
You can query the global and session transaction isolation levels with the following statement:
SELECT @ @global. tx_isolation;
SELECT @ @session. tx_isolation;
SELECT @ @tx_isolation;
Someone on the web uses the Set tx_isolation command:
mysql> set tx_isolation= ' read-committed ';
Query OK, 0 rows Affected (0.00 sec)
+----------------+
| @ @tx_isolation |
+----------------+
| read-committed |
+----------------+
1 row in Set (0.00 sec)
Mysql> SELECT @ @session. tx_isolation;
+------------------------+
| @ @session. tx_isolation |
+------------------------+
| read-committed |
+------------------------+
1 row in Set (0.00 sec)
Transaction isolation has changed.
Someone else on the web wrote the SET @ @tx_isolation command, but this command is problematic.
mysql> SET @ @tx_isolation =' read-committed ';
Query OK, 0 rows Affected (0.00 sec)
Mysql> SELECT @ @session. tx_isolation;
+------------------------+
| @ @session. tx_isolation |
+------------------------+
| Repeatable-read |
+------------------------+
1 row in Set (0.00 sec)
Mysql> SELECT @ @tx_isolation;
+-----------------+
| @ @tx_isolation |
+-----------------+
| Repeatable-read |
+-----------------+
1 row in Set (0.00 sec)
The isolation level of the session does not change.
MySQL SET TRANSACTION isolation level