当前位置:网站首页>Mysql database explanation (V)
Mysql database explanation (V)
2022-06-26 13:18:00 【C chord~】
Catalog
2. Characteristics of the transaction (ACID)
3. The level of transaction isolation ( Four kinds of )
2.1MyISAM Table support 3 Different storage formats
2.2MyISAM Applicable production scenarios
3.2Innodb Store three files on disk
3.3 Applicable to production scenarios
4. Check out the storage engines supported by the system
5. Look at the storage engine that the table uses
introduction
A database transaction is a series of operations performed as a single logical unit of work , Or do it all 、 Or none at all .
One . Business
1. Concept
- A transaction is a mechanism 、 A sequence of operations , Contains a set of database operation commands , And all the commands as a whole to submit or revoke the operation request to the system , That is, this set of database commands is either executed , Either not 2.
- A transaction is an indivisible unit of work logic , When performing concurrent operations on a database system , Transactions are the smallest unit of control
- Transaction is suitable for the scenario of multi-user operating database system at the same time
- Transaction is to ensure data consistency through transaction integrity
2. Characteristics of the transaction (ACID)
Transactions have four characteristics : Atomicity 、 Uniformity 、 Isolation, 、 persistence
2.1 Atomicity
- A transaction is a complete operation , The elements of a transaction are indivisible
- All elements in a transaction must be committed or rolled back as a whole
- If any element in the transaction fails , Then the whole transaction will fail
2.2 Uniformity
- When the transaction is complete , The data must be in a consistent state
- Before the transaction starts , The data stored in the database is in a consistent state
- In an ongoing transaction , The data may be in an inconsistent state
- When the transaction completes successfully , The data must return to a known consistent state
2.3 Isolation,
- All concurrent transactions that modify data are isolated from each other , Indicates that the transaction must be independent , It should not in any way depend on or affect other transactions ( direct influence )
- A transaction that modifies data can access that data before another transaction that uses the same data starts , Or access the data after another transaction using the same data ends
The interaction of transactions is divided into 4 Kind of
- Dirty reading : Read uncommitted data
- It can't be read repeatedly : The data read many times before and after is inconsistent
- Fantasy reading : Data is read many times , The total amount of data is inconsistent ( A transaction modifies the data in a table , This modification involves all data rows in the table . meanwhile , Another transaction also modifies the data in this table , This modification is to insert a new row of data into the table . that , The user operating the previous transaction will find that there are no modified data rows in the table , It's like an illusion .)
- Lost update : Two people modify data at the same time , The data submitted later will overwrite the data submitted earlier
2.4 persistence
- No matter whether the system fails or not , The result of the transaction is permanent
- Once the transaction is committed , The effect of the transaction is permanently preserved in the database
3. The level of transaction isolation ( Four kinds of )
read uncommitted: Read uncommitted data Don't solve dirty reading
read committed: Read submitted data Can solve dirty reading
repeatable read: Duplicate read Can solve dirty reading and It can't be read repeatedly —mysql default
serializable: Serialization Can solve Dirty reading It can't be read repeatedly and Virtual reading — It's like a lock table
4. Transaction statements
- MySQL The database will automatically commit transactions ( Default )
- We also cancel the automatic transaction submission function
- After closing, we need to manually commit the transaction , The transaction you create will not take effect for the database .
Common commands
set autocommit=0; # Disable auto submit
set autocommit=1; # Turn on auto submit ,Mysql The default is 1
set variVARIABLES like 'autocommit'; # see Mysql Medium AUTOCOMMIT value
begin or start transaction or set autocommit-0( Disable auto submit ): Start a transaction
commit or commitwork: Commit transaction , And make all changes made to the database permanent
notes : Yes commit after , Will trigger I/O Write to stream
rollback or rollback work: Rolling back ends the user's transaction , And undo all ongoing uncommitted modifications
savepoint S1: Use savepoint Mark .
Allows you to create a rollback point in a transaction , There can be more than one... In a transaction savepoint;S1 Represents the name of the rollback point
release savepoint Archive point name : Delete archive point
rollback to [savepoint] S1: Roll back the transaction to the marked point
Two . Storage engine
1. Concept
- MySQL The data in is stored in files with various technologies , Each technology uses a different storage mechanism 、 Indexing techniques 、 Lock levels and ultimately provide different functions and capabilities , These different technologies and supporting functions are in MySQL It's called storage engine in
- The storage engine is MySQL Storage mode or storage format of data stored in file system
2.MyISAM
- MyISAM The storage engine is MySQL Relational database 5.5 The default storage engine before version , Formerly known as ISAM
- ISAM It is a well-defined and time tested data table management method , At the time of design, it is considered that the number of times the database is queried is much greater than the number of times the database is updated
2.1 MyISAM Characteristics
- MyISAM Unsupported transaction , Foreign keys are also not supported
- Fast access
- There is no requirement for the integrity of things
- MyISAM Store three files on disk
- .frm Definition of file storage table structure
- The extension of the data file is .MYD (MYData)
- The extension of the index file is .MYI (MYIndex)
- Table level locking form , Lock the entire table when the data is updated ( Two people are not allowed to operate at the same time )
- Databases block each other in the process of reading and writing . It will block the reading of user data in the process of data writing , It will also block the user's data writing in the process of data reading
- Data is written or read separately , The process is fast and takes up less resources
2.1MyISAM Table support 3 Different storage formats
(1) static state ( Fixed length ) surface
Static tables are the default storage format . Fields in static tables are immutable , So every record is a fixed length , The advantage of this storage method is that the storage is very fast , Easy to cache , It's easy to recover in case of failure ; The disadvantage is that it usually takes up more space than a dynamic table .
(2) Dynamic table
Dynamic tables contain variable fields , Records are not fixed length , The advantage of this storage is that it takes up less space , But frequent updates 、 Deleting records will cause fragmentation , It needs to be carried out on a regular basis OPTIMIZE TABLE Sentence or myisamchk -r Command to improve performance , And it's relatively difficult to recover in case of failure .
(3) Compression meter
The compressed table consists of myisamchk Tool creation , Take up a very small space , Because each record is compressed individually , So there's only a very small cost of access .
2.2MyISAM Applicable production scenarios
- Business doesn't need the support of business
- Read or write data unilaterally
- MyISAM The storage engine reads and writes data frequently, which is not suitable for the scenario
- Using read-write concurrency to access relatively low business
- Business with relatively little data modification
- Services that do not require very high consistency of data services
- The server hardware resources are relatively poor
3.innoDB
3.1 characteristic
- Support transactions : Support 4 Transaction isolation levels
- Row level locking , But full table scan will still be table level locking
- Read and write blocking is related to transaction isolation level
- It has very efficient cache properties : Can cache index , Can also cache data
- Tables and primary keys are stored in clusters
- Support partition 、 Table space , similar oracle database
- Support for foreign key constraints ,5.5 Full text indexing was not previously supported ,5.5 Future versions support full-text indexing
- High requirements for hardware resources
notes : because MyISAM Pay attention to reading , and Innodb Pay attention to the function of writing , Therefore, there are differences in table level locking for related search .
3.2Innodb Store three files on disk
- db.opt( Table properties file )
- Table name .frm( Table structure file )
- Table name .ibd( Table data metadata )
3.3 Applicable to production scenarios
- Business needs transaction support
- Row level locking has a good adaptability to high concurrency , But make sure the query is done through the index
- Scenarios where business data is updated frequently , Such as : Forum 、 Microblogging, etc High requirements for business data consistency
- The memory of hardware device is large ( Because transactions are put into memory first ), utilize innodb Better cache capacity to improve memory utilization , Reduce disk IO The pressure of the
4. Check out the storage engines supported by the system
show engines;
5. Look at the storage engine that the table uses
show table status from Library name where name=' Table name '\G;
or
use Library name ;
show create table Table name ;
6. Modify the storage engine
Method 1 :alter Modify table structure
use Library name ;
alter table Table name engine=myisam;
Method 2 : Modify the configuration file
vim /etc/my.cnf
[mysqld]
default-storage-engine=INNODB
Method 3 :create Specify the storage engine when creating the table
use Library name ;
create table Table name ( Field 1 data type ,...) engine=MyISAM;
summary
Database ACID characteristic : Atomicity 、 Uniformity 、 Isolation, 、 persistence
The interaction of transactions is divided into 4 Kind of
- Dirty reading : Read uncommitted data
- It can't be read repeatedly : The data read many times before and after is inconsistent
- Fantasy reading : Data is read many times , The total amount of data is inconsistent ( A transaction modifies the data in a table , This modification involves all data rows in the table . meanwhile , Another transaction also modifies the data in this table , This modification is to insert a new row of data into the table . that , The user operating the previous transaction will find that there are no modified data rows in the table , It's like an illusion .)
- Lost update : Two people modify data at the same time , The data submitted later will overwrite the data submitted earlier
- myisam Suitable when there are no transaction requirements , Use in scenarios with less read-write concurrency
- innoDB It is suitable for those who have business requirements , Use in scenarios where there are many concurrent reads and writes
- MySQL The storage engine is MySQL A component of a database server , Responsible for not executing the actual data in the database I/O operation
- There are many ways to modify the engine , You should use different methods according to the current state of the database
边栏推荐
- 2、并行接口、协议和相关芯片介绍(8080、8060)
- B - Bridging signals
- System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
- Update and download of Beifu EtherCAT XML description file
- Uva11582 [fast power]colossal Fibonacci numbers!
- Analysis of state transition diagram of Beifu NC axis
- Processing polyhedron change
- sql 将数据表b字段值赋值到数据表a中某一列
- Beifu PLC obtains system time, local time, current time zone and system time zone conversion through program
- 8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)
猜你喜欢
![8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)](/img/e7/2fd8ec8d5e5473c7f84f3e3bcedca8.png)
8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)

5月产品升级观察站

适配器模式(Adapter)

Basic methods for network diagnosis and hardware troubleshooting of Beifu EtherCAT module

What are the common categories of software testing?

Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte

橋接模式(Bridge)

Mode pont

倍福TwinCAT3实现CSV、TXT文件读写操作

Beifu twincat3 can read and write CSV and txt files
随机推荐
Beifu cx5130 card replacement and transfer of existing authorization files
Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
What are the common categories of software testing?
Beifu PLC model selection -- how to see whether the motor is a multi turn absolute value encoder or a single turn absolute value encoder
SQL assigns the field value of data table B to a column in data table a
Analysis and protection of heart blood dripping vulnerability (cve-2014-0160)
Processing random generation line animation
Don't mess with full_ Case and parallel_ CASE
Arcpy -- use of insertlayer() function: adding layers to map documents
倍福TwinCAT3 NCI在NC轴界面中的基本配置和测试
Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller
Electron official docs series: Examples
MySQL数据库讲解(三)
倍福PLC实现绝对值编码器原点断电保持---bias的使用
中国剩余定理模板题 互质与非互质
QT . Establishment and use of pri
8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)
享元模式(Flyweight)
MySQL数据库常见故障——遗忘数据库密码
Sinotech software outsourcing