InnoDB is designed for maximum performance when Mysql handles huge amounts of data. Its CPU efficiency is probably unmatched by any other disk-based relational database engine. Innodb is very popular among websites or applications with large amounts of data. Then it doesn’t need to be optimized. The answer is obvious: of course not! ! !
Study plans are easily interrupted, and persistence is not easy. There was a meeting in the company recently and it was necessary to adjust the business direction. It was recommended to learn NodeJS. I knew a little bit about NodeJS before, but I didn’t study it in depth. The syntax of Node is basically the same as client-side JS. In the past six months, few client-side things have been developed. Although my basic knowledge of JS was pretty good, I was unfamiliar with this knowledge. It seems that knowledge is used or lost. If it is not used frequently, it will be forgotten in a short time. So I reviewed the relevant knowledge of JS again. Learned the server and socket knowledge of Node. The MySQL plan was put on hold. On Sunday, I ate, drank, and slept. I was terribly lazy in the morning and stayed up until the afternoon. Without further ado, let’s continue the MySQL optimization series, this time looking at the optimization items of InnoDB. InnoDB’s main
indexis a clustered index, and the index and data share a common table space. For InnoDB, the data is the index, and the index is the data. The biggest difference between the InnoDBcaching mechanism and MyISAM is that InnoDB not only caches indexes, but also caches data.
1. InnoDB cache poolInnoDB cache pool (InnoDB buffer pool) is the key to improving the performance of InnoDB. It can cache both data and indexes. Even other management data (metadata, row-level locks), etc. You can use show variables like 'innodb%pool%'; to view related parameter options.
mysql> show variables like 'innodb%pool%'; +-------------------------------------+----------------+ | Variable_name | Value | +-------------------------------------+----------------+ | innodb_additional_mem_pool_size | 8388608 | | innodb_buffer_pool_dump_at_shutdown | OFF | | innodb_buffer_pool_dump_now | OFF | | innodb_buffer_pool_filename | ib_buffer_pool | | innodb_buffer_pool_instances | 8 | | innodb_buffer_pool_load_abort | OFF | | innodb_buffer_pool_load_at_startup | OFF | | innodb_buffer_pool_load_now | OFF | | innodb_buffer_pool_size | 134217728 | +-------------------------------------+----------------+
innodb_buffer_pool_size
innodb_buffer_pool_size is used to set the size of the InnoDB cache pool (InnoDBBufferPool). The default value is 128M.InnoDB cache The size of the pool has a greater impact on the overall performance of InnoDB. If the current MySQL server is exclusively used as a MySQL service, you can increase the size of this parameter as much as possible.
innodb_buffer_pool_instanceThe default value of innodb_buffer_pool_instance is 1, which means that the InnoDB cache pool is divided into a region. Appropriately increasing the parameter value can improve the concurrency performance of InnoDB.
innodb_additional_mem_pool_sizeSpecify the cache size used by InnoDB to store the data dictionary and other internal data. The default value is 2M. The more tables there are in InnoDB, the more Increase the size of this parameter appropriately.
2. Internal structure of InnoDB cache poolInnoDB maintains a cache pool in memory for caching data and indexes. The cache pool can be thought of as a very long linked list (
list). The linked list is divided into two sub-linked lists, one sub-linked list stores old page data, and the old page data is a data page that has not been accessed for a long time. A sub-linked list stores new page, and new page is the most recently accessed data page. The old page accounts for 37% of the entire linked list size by default, which can be viewed through the innodb_old_blocks_pct parameter.
mysql> show variables like 'innodb_old_blocks%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | innodb_old_blocks_pct | 37 | | innodb_old_blocks_time | 1000 | +------------------------+-------+
The intersection of the old page and the new page is called the midpoint.
When a user accesses data, InnoDB will first search for data in the InnoDB cache. If there is no data in the cache pool, InnoDB will insert the data from the hard disk into the InnoDB cache pool. If the cache pool is full, then Use the LRU algorithm to clear expired old data
3. InnoDB cache pool warm-up.After the MySQL server is started for a period of time, InnoDB will put frequently accessed data (business data, management data) into the InnoDB cache, that is, the InnoDB cache pool stores frequently accessed data ( Referred to as hot data). When the size of the InnoDB cache pool is tens of gigabytes or hundreds of gigabytes, if you restart MySQL, what if you load the hot data in the previous InnoDB cache pool into the InnoDB cache pool?
If you rely solely on InnoDB to preheat the InnoDB cache pool, it will take a long time. For systems with busy business, long-term hangup is a serious production accident and cannot be done. tolerate. Fortunately, MySQL version 5.6 supports saving hot data to the hard disk when shutting down the service. MySQL restarts by first loading the hot data in the hard disk into the InnoDB cache, which can shorten the warm-up time and improve the concurrency of busy business. time efficiency.
mysql> show variables like '%innodb%pool%'; +-------------------------------------+----------------+ | Variable_name | Value | +-------------------------------------+----------------+ | innodb_additional_mem_pool_size | 8388608 | | innodb_buffer_pool_dump_at_shutdown | OFF | | innodb_buffer_pool_dump_now | OFF | | innodb_buffer_pool_filename | ib_buffer_pool | | innodb_buffer_pool_instances | 8 | | innodb_buffer_pool_load_abort | OFF | | innodb_buffer_pool_load_at_startup | OFF | | innodb_buffer_pool_load_now | OFF | | innodb_buffer_pool_size | 134217728 | +-------------------------------------+----------------+
innodb_buffer_pool_dump_at_shutdown
The default is off. If the parameter is turned on and the MySQL service is stopped, the hot data in the InnoDB cache will be will be saved to the hard drive.
innodb_buffer_pool_load_at_starup默认是关闭的,如果开启该参数,启动MySQL服务时,MySQL将本地硬盘的热数据加载到InnoDB缓存池中。 innodb_buffer_pool_dump_now 默认关闭,如果开启该参数,停止MySQL服务时,以手动方式将InnoDB缓存池中的热数据保存到本地硬盘。 innodb_buffer_pool_load_now 默认关闭,如果开启该参数,启动MySQL服务时,以手动方式将本地硬盘的数据加载到InnoDB缓存池中, innodb_buffer_pool_filename 如果开启InnoDB预热功能,停止MySQL服务是,MySQL将InnoDB缓存池中的热数据保存到数据库根目录下,默认文件名是这个参数的值。 开启InnoDB缓存后,可以使用如下命令查看当前InnoDB缓存池预热的状态信息: 这里面的英语都比较简单,就不解释了。 四、InnoDB实时监控show status like 'innodb_buffer%';
+---------------------------------------+-------------+
| Variable_name | Value |
+---------------------------------------+-------------+
| Innodb_buffer_pool_dump_status | not started |
| Innodb_buffer_pool_load_status | not started |
| Innodb_buffer_pool_pages_data | 218 |
| Innodb_buffer_pool_bytes_data | 3571712 |
| Innodb_buffer_pool_pages_dirty | 0 |
| Innodb_buffer_pool_bytes_dirty | 0 |
| Innodb_buffer_pool_pages_flushed | 1 |
| Innodb_buffer_pool_pages_free | 7973 |
| Innodb_buffer_pool_pages_misc | 0 |
| Innodb_buffer_pool_pages_total | 8191 |
| Innodb_buffer_pool_read_ahead_rnd | 0 |
| Innodb_buffer_pool_read_ahead | 0 |
| Innodb_buffer_pool_read_ahead_evicted | 0 |
| Innodb_buffer_pool_read_requests | 1497 |
| Innodb_buffer_pool_reads | 219 |
| Innodb_buffer_pool_wait_free | 0 |
| Innodb_buffer_pool_write_requests | 1 |
+---------------------------------------+-------------+
mysql> show engine innodb status\G
The above is the detailed content of Detailed explanation of InnoDB optimization code for MySQL optimization. For more information, please follow other related articles on the PHP Chinese website!

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools