数据库隔离级别

隔离级别(isolation level):定义了事务与事务之间的隔离程度,隔离级别与并发性是互为矛盾的:
    隔离程度越高,数据库的并发性越差;隔离程度越低,数据库的并发性越好。
ANSI/ISO SQL92标准定义了一些数据库操作的隔离级别:
1.未提交读(read uncommitted)脏读
2.提交读(read committed)非重复读
3.重复读(repeatable read)幻像
4.序列化(serializable)
通过一些现象,可以反映出隔离级别的效果。这些现象有:
1.更新丢失(lost update):当系统允许两个事务同时更新同一数据是,发生更新丢失。
2.脏读(dirty read):当一个事务读取另一个事务尚未提交的修改时,产生脏读。
3.非重复读(nonrepeatable read):同一查询在同一事务中多次进行,由于其他提交事务所做的修改或删除,
    每次返回不同的结果集,此时发生非重复读。(A transaction rereads data it has previously read and 
    finds that another committed transaction has modified or deleted the data. )
4.幻像(phantom read):同一查询在同一事务中多次进行,由于其他提交事务所做的插入操作,每次返回不同
    的结果集,此时发生幻像读。(A transaction reexecutes a query returning a set of rows that satisfies 
    a search condition and finds that another committed transaction has inserted additional rows that satisfy the condition. )
                    Dirty Read        NonRepeatable Read        Phantom Read
Read uncommitted    Possible        Possible                Possible
Read committed        Not possible    Possible                Possible
Repeatable read        Not possible    Not possible            Possible
Serializable        Not possible    Not possible            Not possible
------------------------------------------------------------------------------------------------------------------------------
ORACLE提供了SQL92标准中的read committed和serializable,同时提供了非SQL92标准的read-only。
ORACLE缺省的事务隔离级别:read committed
---------------------------------------------------------------------------------------------------------------------
mysql:
修改隔离级别:
    set session|global transaction isolation level read uncommitted;//(Read uncommittedRead committedRepeatable readSerializable)
查看隔离级别:
    select @@tx_isolation;
    select @@global.tx_isolation;
修改事务非自动提交:
    set autocommit=off;  
查看事务提交机制:
    select @@autocommit; 
查看数据表里的锁:
    select * from information_schema.innodb_locks;
开启事务:
    start transaction; 或
    begin;

 

 

posted @ 2017-09-26 15:25  依然是等待  阅读(456)  评论(0编辑  收藏  举报