MySQL- Affairs

1. The concept of transaction

  • Transaction: A transaction is composed of one or more SQL statements individual units constituting, in this unit, each statement is interdependent.
  • Descriptive understand: this separate unit as a whole, if the government in a statement execution failure or an error, the entire unit will be rolled back. All data affected will return to the previous state of affairs began; only when the unit all the statements are executed successfully, the transaction will be successfully executed.
  • Storage engine: use different storage technologies in MySQL to store data in a file or memory.
    • show engines: You can view the mysql storage engine support;
    • Common storage engine: innodb, myisam, memory. Of these, only innodbsupport transaction mechanism.

2. The properties of transactions (ACID)

  • Atomicity (Atomicity)
    transaction is an indivisible unit of work, as the atoms in general. Operations in a transaction either have occurred or not occurred.
  • Consistency (Consistency)
    transaction must transform the database from one consistent state to another consistent state.
  • Isolation (Isolation)
    executing a transaction can not be interfere with other transactions, and data used in the operation of an internal transaction other concurrent transactions are isolated and can not interfere with each other between the respective transaction executed concurrently.
  • Persistent (Durability)
    Once a transaction is committed, he changed data in the database is permanent, even next to other operations failed database should not have any effect on it.

3. The database isolation level

  • Set isolation level is not a problem caused by:
    • Dirty read: for two transactions T1, T2; T1 T2 reading the field has been updated but not yet committed. If rollback T2, T1 reads the contents of the temporary and is valid.
    • Non-repeatable read: For transaction T1, T2; T1 reading a field and the field update T2. T1 when the field is read again, and the last value read differs.
    • Magic Reading: for two transactions T1, T2; T1 reading of a field from a table, and then insert a row T2 Some rows in the table; T1 when the table again read the same, will be more lines .
  • Isolation Levels
    • The need for isolation level settings: avoid concurrency issues each transaction.
    • ** Uncommitted Read (read uncommited): ** allows transactions to read data from other transactions is not submitted; possible problems: 脏读, 不可重复读, 幻读.
    • ** Read Committed (read commited): ** only allowed to read the changes have been submitted by other transactions. Avoid dirty reads, possible 不可重复读problems: 幻读, .
    • ** repeatable degrees (repeatable read): ** ensure that the transaction can be read from the same value from a plurality of fields. The duration of the transaction, other transactions prohibited on this field to be updated. Problems may arise 幻读.
    • ** serialization (serializable): ** ensure that a transaction can always read the same row in the table. The duration of the transaction, other prohibited transaction execution the table insert, update, and delete operations. Though all concurrency problems can be avoided but poor performance.
Published 32 original articles · won praise 7 · views 7580

Guess you like

Origin blog.csdn.net/Isaacddx/article/details/87708562