MySQL-MySQL-Transaction & Index-Database 03

MySQL-MySQL-Transaction & Index-Database 03

Affairs

Either all succeed or all fail

Business principles:

ACID

A: Atomicity: Either all are completed or not completed

C: Consistent transfer, the total amount is the same, and the integrity before and after the transaction is guaranteed to be consistent

I: Isolation When multiple users access the database concurrently, the transaction opened by the database for each user cannot be interfered by the operation data of other transactions

D: The persistent transaction is not committed and restored to its original state; it has been committed and is persisted to the database, irreversible

Problems caused by isolation

Dirty read

Non-repeatable

False reading

Execute transaction

mysql defaults to open transaction default commit

set autocommit =0 turn off autocommit

START TRANSCATION; transaction start

Commit; submit

Rollback; roll back

Set autocommit=1 Turn on autocommit

Savapoint save point

index

Data structure to help MySQL obtain data efficiently

Primary key index (primary key)

Unique identifier, cannot be repeated

Unique index (unique key)

Avoid the appearance of duplicate columns, the unique index can be repeated

Regular index (key | index)

Default index key

Full-text index

Quickly locate data fulltest index

Use of index

When creating the table, add the field so

After creating, add index

show index from student

The difference is very obvious when indexing a large number of queries

Index principle

Indexes are not as many as possible

Do not index fields with a lot of changing data

Tables with small data volumes do not need to be indexed

Indexes are generally added to values ​​that are not frequently modified

Guess you like

Origin blog.csdn.net/rr18758236029/article/details/108517672