Mysql default transaction isolation levels are Read Uncommitted, Read Committed, Repeatable Read and Serializable. 1. Read Uncommitted, which means that under this isolation level, transactions can read uncommitted data of other transactions; 2. Read Committed, which means that under this isolation level, transactions can only read data that has been submitted; 3. Repeatable Read etc.
MySQL has four default transaction isolation levels, namely Read Uncommitted (read uncommitted), Read Committed (read committed), Repeatable Read (repeatable reading) and Serializable (serialization). Each isolation level will be introduced and explained in detail below.
1. Read Uncommitted: means that under this isolation level, transactions can read uncommitted data from other transactions. This isolation level is the lowest and will cause dirty reads (Dirty Read) question. Dirty reading means that after a transaction reads data from another uncommitted transaction, if the transaction is rolled back, the read data will be invalid.
2. Read Committed: means that under this isolation level, transactions can only read submitted data. This isolation level can solve the problem of dirty reads, but will cause non-repeatable reads. Read) question. Non-repeatable reading means that when the same data is read multiple times within a transaction, the reading results are inconsistent.
3. Repeatable Read: means that under this isolation level, transactions can read the same data repeatedly, and the read results are always consistent. This isolation level can solve the problem of non-repeatable reads, but it will cause phantom reads (Phantom Read) question. Phantom reading means that the same query is executed multiple times within a transaction, and new data that meets the conditions is added to the result set.
4. Serializable: means that under this isolation level, transactions are executed strictly sequentially, and concurrent execution is not allowed. This isolation level can solve the problem of phantom reads, but it will affect the concurrency performance of the system.
In addition to the above four isolation levels, MySQL also provides a special isolation level by default, namely the default isolation level (Default). The default isolation level is determined by the server's global variable sql_mode. If sql_mode is STRICT_ALL_TABLES, STRICT_TRANS_TABLES, or a combination of STRICT_ALL_TABLES and STRICT_TRANS_TABLES, the default isolation level is REPEATABLE READ. If sql_mode does not contain the above value, the default isolation level is READ COMMITTED.
In practical applications, it is very important to choose the appropriate isolation level. If the application has higher requirements for data consistency, you can choose a higher isolation level, such as Repeatable Read or Serializable. If you have lower requirements for data consistency and higher requirements for concurrency performance, you can choose a lower isolation level, such as Read Committed.
In addition, MySQL also provides a method to set the transaction isolation level. The transaction isolation level can be modified by setting the session-level or global-level variable transaction_isolation. For example, you can modify the isolation level to Read using the following statement Committed:
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
In summary, MySQL's default transaction isolation levels include Read Uncommitted, Read Committed, Repeatable Read, Serializable and default isolation levels. Choosing the appropriate isolation level is important to ensure data consistency and improve concurrency performance.
The above is the detailed content of What are the default transaction isolation levels of mysql?. For more information, please follow other related articles on the PHP Chinese website!