Server version: 5.6.21-log MySQL Community Server (GPL)
前提提要:
我們知道MySQL的RR(repeatable read)隔離級別下,事務無法看到正在活躍的事務所做的操作包括提交后的。
一般手動開啟事務的命令是begin或start transaction;我以前的理解是一旦執行這條語句就已經開啟了事務,也就是事務id已經生成(可用於MVCC版本比較)。如果事務A和事務B一起執行begin,事務A的所有操作的提交事務B都看不到;
事實是否定的;
環境:
mysql> show variables like 'tx_iso%'; +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | tx_isolation | REPEATABLE-READ | +---------------+-----------------+ 1 row in set (0.00 sec) mysql> show variables like 'auto%'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | auto_increment_increment | 1 | | auto_increment_offset | 1 | | autocommit | ON | | automatic_sp_privileges | ON | +--------------------------+-------+ 4 rows in set (0.00 sec) mysql> show create table t12; +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | t12 | CREATE TABLE `t12` ( `a` int(10) unsigned NOT NULL AUTO_INCREMENT, `b` varchar(766) DEFAULT NULL, `c` int(11) DEFAULT NULL, PRIMARY KEY (`a`), KEY `b` (`b`) ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 | +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
實驗結果是:事務B在未提交和為回滾的情況下,看到了事務A提交的數據;
一旦begin命令之后緊跟着select語句就開啟了事務;或者以start transaction with consistent snapshot開始事務,就無法看到事務A提交的數據;
也就是實現了非鎖定一致性讀;
結論:通過命令begin;start transaction;開始事務,實際上並沒有達到完全的可重復讀;