search
HomeDatabaseMysql Tutorial数据库隔离级别介绍

数据库隔离级别介绍

Jun 07, 2016 pm 03:11 PM
transactionintroducedatadatabaselevelisolation

事物(transaction)是数据库管理系统的执行单位,可以是一个数据库操作(如select操作) 或者是一组操作系列。事物的acid属性,即原子性(atomicty)、一致性(consistency)、隔离性(Isolation)、持久性(Durability)。 原子性 : 保证事物中的所有操作全

  事物(transaction)是数据库管理系统的执行单位,可以是一个数据库操作(如select操作) 或者是一组操作系列。事物的acid属性,即原子性(atomicty)、一致性(consistency)、隔离性(Isolation)、持久性(Durability)。

原子性 : 保证事物中的所有操作全部执行或者全部不执行,比如说执行一个事物,要么全部执行完成,要么回滚到执行之前,拿银行转账事物来说吧,要么转账成功,要么转账失败!!成功,两个金额账户发生变化,一个增加,一个减少,失败的话,两个账户金额保持不变,不会出现一个账户多了钱,一个账户少了钱!!!


一致性:保证数据库始终保持数据的一致性  -- 事物操作之前和事物操作之后是一致的。上面银行转账的例子就是,不管事物执行成功与否,两个账户之间的总金额在执行前后是一致的!!


隔离性: 多个事物并发执行的话结果应该与多个事物串行执行一样的。如果每个事物都串行执行的话,效率会非常的低,所有有些操作在保持数据安全一致的情况下可以冰法执行!!!!!比如说:两个不同的事物读取同一批数据,这样完全可以并发执行,为了控制并发执行的效果就有了不同的隔离级别!!


持久性:持久性表示事务执行完成之后,对数据库的影响是持久的,即使数据库因故障而受到破坏,对数据库也应该能够恢复!!!通常实现方式是采用日志。。




  事物隔离级别(transaction ioslation levels): 隔离级别就是对事务并发控制的等级。ANSI / ISO SQL将其分为串行化(Serializable)、可重复读(REPEATABLE READ)、读已提交(READ COMMIT)、读未提交(READ UNCOMMITED)四个等级。为了实现隔离级别通常数据库采用锁(LOCK)。一般在编程的时候隔离级别,至于具体采用什么锁则由数据库来设置!!


串行化(Serializable):所有的事务都一个接一个的串行执行,这样可以避免幻读(phantomreads)。对于基于锁来实现并发控制的数据库来说,串行化要求在执行范围查询(如选取年龄在10 到 30之间的用户)的时候,需要获取范围锁(range lock)。如果不是基于锁实现并发控制数据库,则检测到有违反串行化操作的事务时,需要滚回该事物。


可重复读(REPEATBLE):所有被select获取的数据都不能被修改,这样可以避免一个事物前后读取出数据不一致的情况。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment