国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Database Mysql Tutorial what is mysql innodb

what is mysql innodb

Apr 14, 2023 am 10:19 AM
mysql innodb

InnoDB is one of the database engines of MySQL. It is now the default storage engine of MySQL and one of the standards for binary releases by MySQL AB. InnoDB adopts a dual-track authorization system, one is GPL authorization and the other is proprietary software authorization. . InnoDB is the preferred engine for transactional databases and supports transaction security tables (ACID); InnoDB supports row-level locks, which can support concurrency to the greatest extent. Row-level locks are implemented by the storage engine layer.

what is mysql innodb

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

If you want to see the storage engine used by your database by default, you can use the command SHOW VARIABLES LIKE 'storage_engine';

1. InnoDB storage engine

InnoDB is one of the database engines of MySQL. It is now the default storage engine of MySQL and one of the standards for binary releases by MySQL AB. InnoDB was developed by Innobase Oy and acquired by Oracle in May 2006. Compared with traditional ISAM and MyISAM, the biggest feature of InnoDB is that it supports ACID-compatible transaction (Transaction) function, similar to PostgreSQL.

InnoDB adopts a dual-track licensing system, one is GPL licensing and the other is proprietary software licensing.

1. InnoDB is the preferred engine for transactional databases and supports transaction security tables (ACID)

ACID attributes of transactions: That is, atomicity and consistency , Isolation, durability

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??????? been To roll back to the point where the transaction started.

This is implemented: is mainly based on the Redo and UNDO mechanism of MySQ log system. A transaction is a set of SQL statements that have functions such as selection, query, and deletion. There will be one node for each statement execution. For example, after the delete statement is executed, a record is saved in the transaction. This record stores when and what we did. If something goes wrong, it will be rolled back to the original position. What I have done has been stored in the redo, and then it can be executed in reverse.

## ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?(eg: For example, if A transfers money to B, it is impossible that A deducts the money but B does not receive it)

## There is no interference between different transactions for the same data;


# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?A transaction is modifying a certain data multiple times, and the multiple modifications in this transaction have not yet been committed. At this time, a concurrent transaction accesses the data, which will cause the data obtained by the two transactions to be inconsistent); (read Fetched uncommitted dirty data from another transaction)

## ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Data, multiple queries within a transaction range returned different data values. This is because it was modified and submitted by another transaction during the query interval; (the data submitted by the previous transaction was read, and the same data values ??were queried. A data item)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Virtual read (phantom read) : It is a phenomenon that occurs when transactions are not executed independently (eg: transaction T1 reads all rows in a table A data item was modified from "1" to "2". At this time, transaction T2 inserted a row of data items into the table, and the value of this data item was still "1" and submitted to the database. If the user operating transaction T1 looks at the data that was just modified, he will find that there is still one row that has not been modified. In fact, this row was added from transaction T2, as if he was hallucinating. ; : After the transaction is completed, all updates to the database by the transaction will be saved to the database and cannot be rolled back 2. InnoDB is the default storage engine of mySQL. The default isolation level is RR, and in RR Taking the isolation level a step further, multi-version concurrency control (MVCC) is used to solve the non-repeatable read problem, and gap locks (that is, concurrency control) are added to solve the phantom read problem. Therefore, InnoDB's RR isolation level actually achieves the effect of serialization level while retaining better concurrency performance. MySQL database provides us with four isolation levels: a, Serializable (serialization): can avoid dirty reads, non-repeatable reads, and phantom reads occurs; b, Repeatable read (repeatable read): can avoid the occurrence of dirty reads and non-repeatable reads;

c, Read committed (read committed): can avoid the occurrence of dirty reads Occurrence;

d, Read uncommitted (read uncommitted): the lowest level, no guarantee in any situation;

from a----d isolation level from high to low, the higher the level , the lower the execution efficiency

3. InnoDB supports row-level locks. Row-level locks can support concurrency to the greatest extent, and row-level locks are implemented by the storage engine layer.

Lock

: The main function of the lock is to manage concurrent access to shared resources and is used to achieve transaction isolation

????????

Type:

Shared lock (read lock), exclusive lock (write lock)

## MySQL Lock strength

: table-level locks (low overhead, low concurrency), usually implemented at the server layer ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? but ? ? ?, will only be implemented at the storage engine level4. InnoDB is designed for maximum performance in processing huge amounts of data. Its CPU efficiency may be unmatched by any disk-based relational database engine

5. The InnoDB storage engine is fully integrated with the MySQL server. The InnoDB storage engine is cached in the main memory. It maintains its own buffer pool for data and indexes. InnoDB places its tables and indexes in a logical table space. The table space can contain several files (or original disk files); 6. InnoDB supports foreign key integrity constraints. When storing data in a table, each table is stored in the order of the primary key. If the primary key is not specified when the table is defined. InnoDB will generate a 6-byte ROWID for each row and use it as the primary key


7. InnoDB is used in many large database sites that require high performance

8. InnoDB does not save the number of rows in the table (eg: when selecting count(*) from table, InnoDB needs to scan the entire table to calculate how many rows there are); when clearing the entire table, InnoDB stores one row Deletion of one row is very slow;

InnoDB does not create a directory. When using InnoDB, MySQL will create a 10MB automatically extended data file named ibdata1 in the MySQL data directory. And two 5MB log files named ib_logfile0 and ib_logfile1

2. The underlying implementation of the InnoDB engine

InnoDB has two storage files, the suffixes are .frm and .idb; .frm is the definition file of the table, and .idb is the data file of the table.

1. The InnoDB engine uses the B Tree structure as the index structure

B-Tree (balanced multi-path search tree): for disks, etc. A balanced search tree designed for external storage devices

When the system reads data from disk to memory, the basic unit is disk block bits. Data located in the same disk block will be read once read out on a regular basis, rather than on demand.

InnoDB storage engine uses pages as data reading units. Pages are the smallest unit of disk management. The default page size is 16k.

The storage space of a disk block in the system is often not that large, so every time InnoDB applies for disk space, it will use several consecutive disk blocks with addresses to reach the page size of 16KB.

InnoDB will use pages as the basic unit when reading disk data into the disk. When querying data, if each piece of data in a page can help locate the data record location, which will reduce the number of disk I/O and improve query efficiency.

The data in the B-Tree structure allows the system to efficiently find the disk block where the data is located

Each node in the B-Tree is based on The actual situation can contain a large amount of keyword information and branches, for example:

what is mysql innodb

Each node occupies one disk block Space, there are two ascending-order keys on a node and three pointers to the root node of the subtree. The pointers store the address of the disk block where the child node is located.

Take the root node as an example. The keywords are 17 and 35. The data range of the subtree pointed to by the P1 pointer is less than 17. The P2 pointerThe data range of the subtree pointed to is 17----35, and the data range of the subtree pointed to by the P3 pointer is greater than 35;

Simulated searchKeywords Process 29:

a. Find disk block 1 based on the root node and read it into memory. [The first disk I/O operation]

b. Compare keyword 29 in the interval (17,35) and find the pointer P2 of disk block 1;

c. Find disk block 3 according to the P2 pointer and read it into the memory. [Disk I/O operation for the second time]

d. Compare keyword 29 in the interval (26, 30) and find pointer P2 of disk block 3;

e. Find disk block 8 according to the P2 pointer and read it into the memory. [Disk I/O operation third time]

f. Keyword 29 was found in the keyword list in disk block 8.

MySQL's InnoDB storage engine is designed with the root node resident in memory, so it strives to achieve a tree depth of no more than 3, that is, I/O does not need to exceed three times;

Analyzing the above results, we found that three disk I/O operations and three memory search operations are required. Since the keywords in the memory are an ordered list structure, binary search can be used to improve efficiency; three disk I/O operations are the decisive factor affecting the entire B-Tree search efficiency.

B Tree

B Tree is an optimization based on B-Tree, making it more suitable Implement the external storage index structure. Each node in B-Tree has key and data, and the storage space of each page is limited. If the data data is large, each node (i.e. one page) will be able to store The number of keys is very small. When the amount of data stored is large, the depth of the B-Tree will also be larger, which will increase the number of disk I/Os during query, thus affecting query efficiency.

In B Tree, all data record nodes are stored on leaf nodes of the same layer in order of key value. Only key value information is stored on non-leaf nodes. This can greatly Increase the number of key values ??stored in each node and reduce the height of B Tree;

B Tree has two changes based on B-Tree: ( 1) The data is stored in leaf nodes

Since the non-leaf nodes of B Tree only store key value information, assuming that each disk block can store 4 key values ??and pointer information, the structure after becoming B Tree is as shown below:

what is mysql innodb

Usually there are two head pointers on the B Tree, one points to the root node, the other points to the leaf node with the smallest keyword, and There is a chain ring structure between all leaf nodes (ie data nodes).

Therefore, two search operations can be performed on B Tree, one is a range search and paging search for the primary key, and the other is a random search starting from the root node.

B Tree in InnoDB

InnoDB is a data storage indexed by ID

There are two data storage files using the InnoDB engine, one is a definition file and the other is a data file.

InnoDB builds an index on the ID through the B Tree structure, and then stores the records in the leaf nodes

what is mysql innodb

##If the indexed field is not the primary key ID, create an index for the field, then store the primary key of the record in the leaf node, and then find the corresponding record through the primary key index

[Related recommendations:

mysql video tutorial]

The above is the detailed content of what is mysql innodb. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Resetting the root password for MySQL server Resetting the root password for MySQL server Jul 03, 2025 am 02:32 AM

To reset the root password of MySQL, please follow the following steps: 1. Stop the MySQL server, use sudosystemctlstopmysql or sudosystemctlstopmysqld; 2. Start MySQL in --skip-grant-tables mode, execute sudomysqld-skip-grant-tables&; 3. Log in to MySQL and execute the corresponding SQL command to modify the password according to the version, such as FLUSHPRIVILEGES;ALTERUSER'root'@'localhost'IDENTIFIEDBY'your_new

Performing logical backups using mysqldump in MySQL Performing logical backups using mysqldump in MySQL Jul 06, 2025 am 02:55 AM

mysqldump is a common tool for performing logical backups of MySQL databases. It generates SQL files containing CREATE and INSERT statements to rebuild the database. 1. It does not back up the original file, but converts the database structure and content into portable SQL commands; 2. It is suitable for small databases or selective recovery, and is not suitable for fast recovery of TB-level data; 3. Common options include --single-transaction, --databases, --all-databases, --routines, etc.; 4. Use mysql command to import during recovery, and can turn off foreign key checks to improve speed; 5. It is recommended to test backup regularly, use compression, and automatic adjustment.

Handling NULL Values in MySQL Columns and Queries Handling NULL Values in MySQL Columns and Queries Jul 05, 2025 am 02:46 AM

When handling NULL values ??in MySQL, please note: 1. When designing the table, the key fields are set to NOTNULL, and optional fields are allowed NULL; 2. ISNULL or ISNOTNULL must be used with = or !=; 3. IFNULL or COALESCE functions can be used to replace the display default values; 4. Be cautious when using NULL values ??directly when inserting or updating, and pay attention to the data source and ORM framework processing methods. NULL represents an unknown value and does not equal any value, including itself. Therefore, be careful when querying, counting, and connecting tables to avoid missing data or logical errors. Rational use of functions and constraints can effectively reduce interference caused by NULL.

Establishing secure remote connections to a MySQL server Establishing secure remote connections to a MySQL server Jul 04, 2025 am 01:44 AM

TosecurelyconnecttoaremoteMySQLserver,useSSHtunneling,configureMySQLforremoteaccess,setfirewallrules,andconsiderSSLencryption.First,establishanSSHtunnelwithssh-L3307:localhost:3306user@remote-server-Nandconnectviamysql-h127.0.0.1-P3307.Second,editMyS

Analyzing the MySQL Slow Query Log to Find Performance Bottlenecks Analyzing the MySQL Slow Query Log to Find Performance Bottlenecks Jul 04, 2025 am 02:46 AM

Turn on MySQL slow query logs and analyze locationable performance issues. 1. Edit the configuration file or dynamically set slow_query_log and long_query_time; 2. The log contains key fields such as Query_time, Lock_time, Rows_examined to assist in judging efficiency bottlenecks; 3. Use mysqldumpslow or pt-query-digest tools to efficiently analyze logs; 4. Optimization suggestions include adding indexes, avoiding SELECT*, splitting complex queries, etc. For example, adding an index to user_id can significantly reduce the number of scanned rows and improve query efficiency.

Aggregating data with GROUP BY and HAVING clauses in MySQL Aggregating data with GROUP BY and HAVING clauses in MySQL Jul 05, 2025 am 02:42 AM

GROUPBY is used to group data by field and perform aggregation operations, and HAVING is used to filter the results after grouping. For example, using GROUPBYcustomer_id can calculate the total consumption amount of each customer; using HAVING can filter out customers with a total consumption of more than 1,000. The non-aggregated fields after SELECT must appear in GROUPBY, and HAVING can be conditionally filtered using an alias or original expressions. Common techniques include counting the number of each group, grouping multiple fields, and filtering with multiple conditions.

Managing Transactions and Locking Behavior in MySQL Managing Transactions and Locking Behavior in MySQL Jul 04, 2025 am 02:24 AM

MySQL transactions and lock mechanisms are key to concurrent control and performance tuning. 1. When using transactions, be sure to explicitly turn on and keep the transactions short to avoid resource occupation and undolog bloating due to long transactions; 2. Locking operations include shared locks and exclusive locks, SELECT...FORUPDATE plus X locks, SELECT...LOCKINSHAREMODE plus S locks, write operations automatically locks, and indexes should be used to reduce the lock granularity; 3. The isolation level is repetitively readable by default, suitable for most scenarios, and modifications should be cautious; 4. Deadlock inspection can analyze the details of the latest deadlock through the SHOWENGINEINNODBSTATUS command, and the optimization methods include unified execution order, increase indexes, and introduce queue systems.

Paginating Results with LIMIT and OFFSET in MySQL Paginating Results with LIMIT and OFFSET in MySQL Jul 05, 2025 am 02:41 AM

MySQL paging is commonly implemented using LIMIT and OFFSET, but its performance is poor under large data volume. 1. LIMIT controls the number of each page, OFFSET controls the starting position, and the syntax is LIMITNOFFSETM; 2. Performance problems are caused by excessive records and discarding OFFSET scans, resulting in low efficiency; 3. Optimization suggestions include using cursor paging, index acceleration, and lazy loading; 4. Cursor paging locates the starting point of the next page through the unique value of the last record of the previous page, avoiding OFFSET, which is suitable for "next page" operation, and is not suitable for random jumps.

See all articles