当前位置:网站首页>Summary of easy-to-use MySQL interview questions (Part 1)
Summary of easy-to-use MySQL interview questions (Part 1)
2022-06-23 02:21:00 【On a sunny day, dolls can only laugh but not cry】
Course introduction :
This set is MySQL The database video tutorial is told by Mr. Du, the teaching director of power node , Which explains in detail MySQL Knowledge about , Include MySQL summary ,MySQL Application environment ,MySQL System features ,MySQL Beginners ,MySQL Management tools , How to install MySQL And MySQL New characteristics , By watching this set Java Video tutorial can master MySQL Full knowledge .
MySQL Introduction to database B Station portal :
https://www.bilibili.com/video/BV1fx411X7BD
What is? MySQL?
MySQL It's a relational database , stay Java Very common in enterprise development , because MySQL It's open source and free , And it's easy to expand . Alibaba database system is also widely used MySQL, So its stability is guaranteed .MySQL It's open source , So anyone can be in GPL(General Public License) Download and modify it according to the needs of personalization .MySQL The default port number for is 3306.
Transaction related ( What is business ?)
A transaction is a logical set of operations , Or both , Either not .
The most classic and often cited example of a transaction is a transfer . If Xiaoming wants to transfer money to Xiaohong 1000 element , There are two key operations involved in this transfer : Reduce Xiao Ming's balance 1000 element , Increase the balance of Xiaohong 1000 element . In case of a sudden error between these two operations, such as the collapse of the banking system , As a result, Xiaoming's balance decreased while Xiaohong's balance did not increase , That's not right . Transaction is to ensure the success of both critical operations , Or they all have to fail .
The four characteristics of things (ACID):
- Atomicity : Transactions are the smallest unit of execution , Division is not allowed . The atomicity of the transaction ensures that the action is either complete , Or it doesn't work at all ;
- Uniformity : Before and after the execution of the transaction , Data consistency , Multiple transactions read the same data with the same result ;
- Isolation, : When accessing the database concurrently , One user's transaction is not interfered by other transactions , The database between concurrent transactions is independent ;
- persistence : After a transaction is committed . Its changes to the data in the database are persistent , Even if the database fails, it should not have any impact .
What are the problems of concurrent transactions ?
In a typical application , Multiple transactions run concurrently , Often operate the same data to complete their own tasks ( Multiple users operate on unified data ). Concurrency is necessary , But it may cause the following problems .
- Dirty reading (Dirty read): When a transaction is accessing data and modifying the data , This modification has not yet been committed to the database , At this time, another transaction also accesses the data , And then I used this data . Because this data is not submitted yet , So the data read by another transaction is “ Dirty data ”, basis “ Dirty data ” The operation may not be correct .
- Missing changes (Lost to modify): When a transaction reads a data , Another transaction also accesses the data , After modifying the data in the first transaction , The second transaction also modifies the data . In this way, the modification result in the first transaction will be lost , So it's called lost modification . for example : Business 1 Read data from a table A=20, Business 2 Also read A=20, Business 1 modify A=A-1, Business 2 Also modify A=A-1, final result A=19, Business 1 The modification of is lost .
- It can't be read repeatedly (Unrepeatableread): Reading the same data multiple times in a transaction . Before the end of the business , Another transaction also accesses the data . that , Between two reads in the first transaction , Due to the modification of the second transaction, the data read by the first transaction twice may be different . This happens when the data read twice in a transaction is different , So it's called unrepeatable reading .
- Fantasy reading (Phantom read): Unreal reading is similar to nonrepeatable reading . It happens in a transaction (T1) Read a few lines of data , Then another concurrent transaction (T2) When some data is inserted . In the subsequent query , The first thing (T1) There will be more records that don't exist , It's like an illusion , So it's called Unreal reading .
The difference between nonrepeatability and unreal reading :
The point of unrepeatable reading is to modify , The point of unreal reading is to add or delete .
example 1( The same conditions , The data you read , Read it again and find that the value is different ): Business 1 Medium A Mr. a read his salary as 1000 The operation of is not finished , Business 2 Medium B Mr. a modified A The salary of is 2000, guide Cause A When I read my salary again, it changed to 2000; This is unrepeatable reading .
example 2( The same conditions , The first 1 Time and number 2 The number of records read is not the same ): The salary in a payroll is greater than 3000 There are 4 people , Business 1 Read all salaries greater than 3000 People who , A total of 4 Bar record , When the transaction 2 Another one is inserted that the salary is greater than 3000 The record of , Business 1 The record found when reading again becomes 5 strip , This leads to unreal reading .
What are the transaction isolation levels ?MySQL The default isolation level for is ?
SQL The standard defines four isolation levels :
- READ-UNCOMMITTED( Read uncommitted ): Lowest isolation level , Allow read of uncommitted data changes , Can cause dirty reading 、 Phantom or unrepeatable reading .
- READ-COMMITTED( Read committed ): Allow to read data submitted by concurrent transactions , Can prevent dirty reading , But phantom or unrepeatable reads can still occur .
- REPEATABLE-READ( Repeatable ): Multiple reads of the same field are consistent , Unless the data is modified by the transaction itself , Can prevent dirty and unrepeatable read , But phantom reading can still happen .
- SERIALIZABLE( Serializable ): Highest isolation level , Completely obey ACID Isolation level . All transactions are executed one by one , In this way, there is no interference between transactions , in other words , This level prevents dirty reads 、 Unrepeatable reading and phantom reading .
MySQL InnoDB The default isolation level supported by the storage engine is REPEATABLE-READ( Can be reread ). We can go through SELECT @@tx_isolation; Order to see
mysql> SELECT @@tx_isolation;
+-----------------+
| @@tx_isolation |
+-----------------+
| REPEATABLE-READ |
+-----------------+
What needs to be noted here is : And SQL The difference in standards is InnoDB Storage engine in REPEATABLE-READ( Can be reread ) The transaction isolation level uses Next-Key Lock Lock algorithm , So we can avoid the production of unreal reading , It works with other database systems ( Such as SQL Server) Is different . So InnoDB The default isolation level supported by the storage engine is REPEATABLE-READ( Can be reread ) The transaction isolation requirements can be fully guaranteed , That is to say SQL The standard SERIALIZABLE( Serializable ) Isolation level .
Because the lower the isolation level , The fewer locks the transaction requests , So the isolation level of most database systems is READ-COMMITTED( Read submissions ):, But what you need to know is InnoDB The storage engine uses... By default REPEATABLE-READ( Can be reread ) There will be no loss of performance .
InnoDB Storage engine in Distributed transactions In general, we use SERIALIZABLE( Serializable ) Isolation level .
To be continued ......
边栏推荐
- Xgboost principle
- 1. Mx6u image burning principle (no specific process)
- Using mock data in vite projects -vite plugin mock
- Custom shapes for ugui skill learning
- How to download online printing on Web pages to local PDF format (manual personal test)
- Bc117 xiaolele walks up the steps
- 1.3-1.4 web page data capture
- Freshman C language summary post (hold change) Part 2 formatted monthly calendar
- Deep scan log4j2 vulnerability using codesec code audit platform
- Solution to the problem of easycvr switching MySQL database traffic statistics cannot be displayed
猜你喜欢

1. Mx6u bare metal program (6) - timer

Rebirth -- C language and the story I have to tell (text)

Li Mu's notes on machine learning -1.2

8. destruct, construct, deep copy, shallow copy, assignment operator overload

Understand GB, gbdt and xgboost step by step

CSDN browser assistant for online translation, calculation, learning and removal of all advertisements

Anaconda creates a new environment encounter pit

Google account cannot be logged in & external links cannot be opened automatically & words with words cannot be used

Pywebio to quickly build web applications

Interviewer: why does TCP shake hands three times and break up four times? Most people can't answer!
随机推荐
Freshman C language summary post (hold change) Part1 output diamond
5g core network and core network evolution
Analog Electronic Technology
pd. read_ CSV and np Differences between loadtext
Deep scan log4j2 vulnerability using codesec code audit platform
Performance test -- 14 detailed explanation of performance test report and precautions
2021-11-11
Aikuai multi dialing + load balancing overlay bandwidth
Primary pointer part
What is a smart farm?
How to make word notes beautiful
Targeted and ready to go
OVS port traffic statistics practice
10. static member variables, static member methods, and pointers to class members
Hypervisor Necromancy; Recover kernel protector (2)
Mobile communication Overview - Architecture
Cut! 39 year old Ali P9 saved 150million
"Initial C language" (Part 2)
Score and loop statements (including goto statements) -part3
Buuctf misc-[bjdctf2020] Nani