"Read Committed" Isolation Level

A tutorial example is provided on the 'Read Uncommitted' isolation level, where 'non-repeatable read' and other concurrent transactions phenomena could occur.

My next test is about "read committed". Again, I used with two command window sessions.

mysql> SELECT 'Session 1';
+-----------+
| Session 1 |
+-----------+ 
mysql> DROP TABLE IF EXISTS User;
mysql> CREATE TABLE User (ID INT PRIMARY KEY, Name CHAR(8))
   ENGINE=InnoDB;
mysql> INSERT INTO User VALUES (2, 'bill');

                              mysql> SELECT 'Session 2';
                              +-----------+
                              | Session 2 |
                              +-----------+ 
                              mysql> SET TRANSACTION ISOLATION LEVEL 
                                 READ COMMITTED;
                              mysql> START TRANSACTION;
                              mysql> SELECT * FROM User WHERE ID=2;
                              +----+------+
                              |  2 | bill |
                              +----+------+

mysql> UPDATE User SET Name='bob' WHERE ID=2;

                              mysql> SELECT * FROM User WHERE ID=2;
                              +----+------+
                              |  2 | bob  |
                              +----+------+
                                  (Non-repeatable read)

The result clearly shows that "non-repeatable read" could indeed happen in a transaction with "read committed" isolation level. In session 2, the second "SELECT * FROM User WHERE ID=2" statement returned different data than the first "SELECT * FROM User WHERE ID=2" statement.

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

 Commonly Used Functions

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

 Using SELECT to Query Database

Transaction Management and Isolation Levels

 What Is a Transaction?

 Transaction Management in MySQL

 Transaction Isolation Levels

 "Read Uncommitted" Isolation Level

"Read Committed" Isolation Level

 "Repeatable Read" Isolation Level

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version