Database study notes (nine Dian transaction characteristics)

A transaction is composed of a group of DML statements, which are logically related. This group of DML statements either all succeed or all fail, which is a whole. MySQL provides a mechanism to ensure that we achieve this effect. The transaction also provides for different clients see the data is not the same.
Begins a transaction

start transaction;

Creating a save point

savepoint 保存点名;

Back to save point (depending on the circumstances)

rollback to 保存点名;

Transaction operation considerations

  • If no save points, you can also roll back, only to begin to roll back the transaction. Use rollback directly (provided that the transaction has not been committed)
  • If a transaction is submitted to (commit), you can not rollback (rollback)
  • Which point you can choose to save fallback
  • InnoDB supports transactions, MyISAM does not support transactions
  • Start transaction can use
    the isolation level of start transaction transaction.
    When we have multiple clients operating a table of the database at the same time, MySQL provides an isolation level for isolation operations.
    When the MySQL table is opened by multiple threads or clients to operate the data in the database, MySQL provides a mechanism that allows different transactions to be isolated when operating data. Thereby ensuring data consistency. Dirty read
    without isolation

    Means that when a transaction is accessing data, and the data has been modified, and this modification has not been submitted to the database, then, another transaction also access the data, and then use this data.

Non-repeatable read

It refers to a transaction, reading the same data multiple times. When this transaction is not over, another transaction also access the same data. So, between the two read data in the first transaction, due to the modification of the second transaction, then the first two transactions read data may be different. This happens that the data read twice in a transaction is different, so it is called non-repeatable read. (That is, the same data content cannot be read).

Magic Reading

Refers to a phenomenon that occurs when the transaction is not executed independently, for example, the first transaction modifies the data in a table, and this modification involves all data rows in the table. At the same time, the second transaction also modifies the data in this table. This modification is to insert a new row of data into the table. Then, the user operates the first transaction will occur after the discovery of the table there is no modification of the data lines, as if the same happened hallucinations.

Note: The key point of non-repeatable reading is modification. For the same condition, the data you have read is different. Magic Reading focus is to add or remove, for the same condition, read out the 1st and 2nd number of records that are not the same.
Database study notes (nine Dian transaction characteristics)
Set transaction isolation level

set session transaction isolation level read uncommitted;

ACID characteristics of transactions

  • Atomicity (Atomicity):
    transaction application is the smallest unit of execution, as is the atomic nature of the smallest particles, having the same characteristics can not be divided, the transaction applications is not subdivided smallest logical execution bodies.
  • Consistency (Consistency):
    As a result of transaction execution, the database must be changed from a consistent state to another consistent state. When the database contains only the outcome of the transaction successfully committed, the database is in a consistent state. If the system is running an interrupt occurs, a transaction was interrupted while not yet complete, but changed incomplete transactions have been written to the database modifications made to the database, then the database will be in a incorrect (inconsistent) state. Consistency is therefore ensured by atomic.
    of.
  • Isolation:
    The execution of each transaction does not interfere with each other, and the internal operations of any transaction are isolated from other concurrent transactions. In other words, concurrently executed transactions cannot see each other's intermediate state, and concurrently executed transactions cannot affect each other.
  • Persistent (Durability):
    Persistence means that once a transaction is committed, it changes made to the database records to be permanently stored therein (such as: disk).

Guess you like

Origin blog.51cto.com/14289397/2546430