Database transaction, the four characteristics of the transaction, MySQL supports transactions

Database transactions:

The transaction database is a piece of atomic batch indivisible sql statement,
the batch is either all executed or rollback (rollback) is not executed.

MYSQL transaction There are two main methods:

1, with BEGIN, ROLLBACK, COMMIT BEGIN begin to implement a transaction COMMIT ROLLBACK transaction rollback a transaction confirmation

2, the SET directly to the changed MySQL Autocommit mode: SET AUTOCOMMIT = 0 disables automatic submission SET AUTOCOMMIT = 1 enable auto-commit

Affairs of the four properties ACID:

atomicity (Atomicity)
first atomic, this is the most simple. He said that all operations together make up an atom within a package of things, either all succeed, or all fail. This is the most basic features to ensure that the database because other factors lead to abnormal or downtime.

consistency (Consistency)
Second consistency, this is the most misunderstood of all, a lot of blog like to use the example of a bank transfer has been speaking of the so-called agreement is based on atomic.

Atomicity only guarantee the identity of all operations in one thing, it was all life and death, will not you die, I'm still alive. However, there is no guarantee atomicity and everyone living together the same time, die together. Computer instruction is a sequential, so it decided to submit a thing, will go through a process of time, so if something were to submit a half, I read a database, will read the intermediate results?

In order to prevent such a situation, the consistency of the database before and after the things it provides for submission of things, always will be, there may be state before and after the submission of the state of things and things submission, from a consistent state to another consistent state, but can not state occurs in the middle of the process. That something is the result of the implementation of a quantum state, rather than a linear state.

And the database will be submitted to a process of things, if the time of filing, there is a time lag, in the first seconds of submission, a deletion process is not yet complete to the third seconds to complete, will visit the first seconds of the third seconds people visit a different result? Inconsistent, the state of chaos? This is the only guarantee consistency was there before and after the state of the state, will not appear intermediate states.

isolation (Isolation)
isolation of things, based on atomic and consistency, as things are atomized, quantized, so that things can be in the form of a plurality of packets of atoms concurrently, but each thing interfering .

However, since more things could operate the same resources, different things in order to ensure isolation, there will be many lock program, of course, is to achieve the database, how to achieve them, we do not have to get to the bottom.

persistent (Durability)
persistence, after submission of a thing, the database state has changed forever, as long as this thing has submitted, even if submitted after the downtime, he indeed submitted, does not appear because

Just goes down and let the submission does not take effect, to submit something, he is like indelible tattoo, cured forever, unless you destroy the hard drive.

--------------------https://blog.csdn.net/qq_25448409/article/details/78110430?utm_source=copy

Published 28 original articles · won praise 24 · views 10000 +

Guess you like

Origin blog.csdn.net/XM_no_homework/article/details/104426618