Home Database Mysql Tutorial Detailed explanation of examples of InnoDB database optimization

Detailed explanation of examples of InnoDB database optimization

May 24, 2017 pm 01:53 PM
innodb mysql optimization

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. Recently, there was a meeting in the company to adjust the business direction, so I suggested learning 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

index

is 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 pool

InnoDB 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   |
+-------------------------------------+----------------+
Copy after login

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_instance

The 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_size

Specify 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 pool

InnoDB 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 |
+------------------------+-------+
Copy after login

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   |
+-------------------------------------+----------------+
Copy after login

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

The default is off. If this parameter is turned on, when starting the MySQL service, MySQL will load hot data from the local hard disk into the InnoDB cache pool.

innodb_buffer_pool_dump_now

默认关闭,如果开启该参数,停止MySQL服务时,以手动方式将InnoDB缓存池中的热数据保存到本地硬盘。

innodb_buffer_pool_load_now

默认关闭,如果开启该参数,启动MySQL服务时,以手动方式将本地硬盘的数据加载到InnoDB缓存池中,

innodb_buffer_pool_filename

如果开启InnoDB预热功能,停止MySQL服务是,MySQL将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      |
+---------------------------------------+-------------+
Copy after login

这里面的英语都比较简单,就不解释了。

四、InnoDB实时监控

mysql> show engine innodb status\G

<br>

【相关推荐】

1. Mysql免费视频教程

2. 详解innodb_index_stats导入数据时 提示表主键冲突的错误

3. 实例详解 mysql中innodb_autoinc_lock_mode

4. MySQL中添加新用户权限的实例详解

5. 实例详解mysql中init_connect方法

The above is the detailed content of Detailed explanation of examples of InnoDB database optimization. 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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

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.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

See all articles