Small shell _mysql storage engine and transaction concepts

Source: Internet
Author: User
Tags bulk insert

storage engine and transaction concepts Brief:
1. What is a storage engine
2. What is a transaction

first, the storage engine

the way to store and manage data in layman's words

Image examples:

A bicycle keeper in a place: Lee, Zhang. Every day there are many people to access bicycles. Lee's Management method is: The owner of their own storage, Lee also does not record what the other store is what the car. When you pick up your car, you pay a management fee. Also do not check whether the other's own car. On the contrary, Zhang, when the owner of the car storage, record the characteristics of the store and the corresponding vehicle information. When people come to pick up the car, Zhang must also carefully check, the characteristics of the car and whether the corresponding.

From the above example:

A, from the point of view of efficiency: Lee is faster than Zhang, because it does not have to proofread

b, from a security point of view: Zhang than Lee to be safe, because it was proofread.

Summary: In fact, the MySQL storage engine is the same, each storage engine has its own access mode, so in the choice, should be based on the actual situation.

1. How to view MySQL engine

Mysql> show engines;

2, the common storage engine MyISAM and the InnoDB difference

2.1. MyISAM: Fast BULK INSERT, no transaction support, table lock

InnoDB: Bulk Insert speed is relatively slow, support transactions, row locks

Second, the business

Generally understood, refers to a set of operations, either successfully executed, or not executed.

For example:

User A transfers 500 RMB to User B

First Analyze This process:

1, determine whether the card balance of user A is greater than 500 yuan, otherwise, will not be able to transfer operations

2, in the satisfaction of more than 500 yuan, based on user A to User B to transfer

3, the transfer operation is successful, then user A's card balance minus 500 yuan, User B plus 500 yuan

Use the program to describe the process

</pre><p><pre name= "code" class= "php" ><?php$usera = $momeyA; $userB = $momeyB; if ($moneyA < 500) {return false;} $sqlA = "Update user set money=money-500 where name= ' UserA '";   Step A$resulta = $db->query ($sqlA), if ($resultA) {$sqlB = "Update user set money=money+500 where name= ' UserB '";//Step B$re SULTB = $db->query ($sqlB); if ($resultB) {return true;} else{$sqlA = "Update user set money=money+500 where name= ' UserA '";//Step C$resulta = $db->query ($sqlA); return false;}} $sqlA = "Update user set money=money+500 where name= ' UserA '";//Step D$resulta = $db->query ($sqlA); return false;? >


From a transactional point of view:

1. In the course of the transfer, there is a mistake, the error for both parties, there is no impact. That is impossible because of an error, user A is reduced by 500, and User B is inexplicably 500 more

2, in the transfer process, user A is not able to see their card balance minus 500, and User B is unable to see themselves increase of 500 yuan, because the transfer operation is not over.

3. From this process alone, the total amount of User A and User B is constant. Only one side is reduced and the other side increases

Summary of several features of the transaction

A, atomicity: a set of operations, either successfully executed, or not executed

B, Isolation: No other session can see the process of intermediate changes until all operations have been completed

C, Consistency: The total amount of data is still matched before and after the transaction occurs

D, Persistence: The impact of a transaction cannot be revoked


The quieter become,the more you is able to hear!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Small shell _mysql storage engine and transaction concepts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.