隔離性
隔離級別
如果沒有隔離級別
涉及到的資料命令
begin 開始事務
commit 提交事務'
rollback 事務回滾
禁止自動提交
set autocommit = 0
設定隔離級別
set tx_isolation = 'read-uncommitted'
read-uncommitted 讀取未提交
set tx_isolation = 'read-uncommitted';
set autocommit =0;
# 檢視自動提交的是否關閉
select @@autocommit;
# 開啟事務
start transaction ;
update tb_user set price=500 where username='zhangsan';
rollback
set tx_isolation = 'read-uncommitted';
set autocommit =0;
select price from tb_user where uid=10
read-committed 能解決髒讀的情況
sqlserver
oracle
set tx_isolation = 'read-committed';
set autocommit =0;
# 檢視自動提交的是否關閉
select @@autocommit;
# 開啟事務
start transaction ;
update tb_user set price=500 where username='zhangsan';
rollback
set tx_isolation = 'read-commited';
set autocommit =0;
select price from tb_user where uid=10
repeatable read (讀取多行資料 新增 刪除)
set tx_isolation = 'repeatable-read';
set autocommit =0;
start transaction ;
insert into tb_user (username, password, price)values ('1234','123',10000);
commit
set tx_isolation = 'repeatable-read';
set autocommit =0;
start transaction ;
select * from tb_user;
update tb_user set price=1 where uid=2;
commit
select * from tb_user ;
實現原理
日誌redo log 重做日誌
undo log
主從複製 讀寫分離 bin log
mysql隔離級別 簡書 MySQL 事務隔離級別
1 讀未提交 髒讀 未授權讀取 解釋兩個事務同時進行,事務2讀取到了事務1修改了 但還沒有完成事務commit的資料 2 讀已提交 不可重複讀 授權讀取 解釋乙個事務中,可以讀取到其他事務提交的資料,所以說,在這個事務中針對乙個資料的多次讀取 重複讀 可能會存在不同的值 3 可重複讀 幻讀 解釋乙個...
mysql隔離級別 簡書 MySQL事務的隔離級別
一 事務的基本要素 acid 1 原子性 atomicity 事務開始後所有操作,要麼全部做完,要麼全部不做,不可能停滯在中間環節。事務執行過程 錯,會回滾到事務開始前的狀態,所有的操作就像沒有發生一樣。也就是說事務是乙個不可分割的整體,就像化學中學過的原子,是物質構成的基本單位。2 一致性 con...
mysql隔離級別 MySQL 事務隔離級別
mysql innodb所提供的事務滿足acid的要求,事務是通過事務日誌中的redo log和undo log來實現原子性 undo log 一致性 undo log 永續性 redo log 事務通過鎖機制實現隔離性。1 事務隔離級別與實現read uncommitted 讀未提交 read c...