Relevant introduction to mysql optimization insert performance
mysql insert statement syntax
insert into `table`(`field1`,`field2`) values('value1','value2');
Methods to improve insert performance
1. One The sql statement to insert multiple pieces of data
INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_0', 'content_0', 0); INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_1', 'content_1', 1);
can be written as
INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_0', 'content_0', 0), ('userid_1', 'content_1', 1);
2. Use transactions
START TRANSACTION; INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_0', 'content_0', 0); INSERT INTO `insert_table` (`uid`, `content`, `type`) VALUES ('userid_1', 'content_1', 1); ... COMMIT;
Note
1. There is a limit on the length of sql statements. Please pay attention when merging sql statements. The length limit can be modified through the max_allowed_packet configuration item, and the default is 1M.
2. If the transaction is too large, it will affect the execution efficiency. Mysql has the innodb_log_buffer_size configuration item. If it exceeds this value, disk data will be used, which will affect the execution efficiency.
Description of configuration items about transactions:
innodb_buffer_pool_size
If you use Innodb, then this is an important variable. Compared to MyISAM, Innodb is more sensitive to buffer size. MySIAM may be fine using the default key_buffer_size for large amounts of data, but Innodb feels slow when using the default value for large amounts of data. Innodb's buffer pool will cache data and indexes, so there is no need to leave space for the system cache. If you only use Innodb, you can set this value to 70%-80% of the memory. Same as key_buffer, if the amount of data is relatively small and does not increase much, then do not set this value too high to increase memory usage.
innodb_additional_pool_size
The effect of this is not very obvious, at least when the operating system can allocate memory reasonably. But you may still need to set it to 20M or more to see how much memory Innodb will allocate for other uses.
innodb_log_file_size
It is very important when writing a lot, especially large amounts of data. Be aware that larger files provide higher performance, but database recovery will take more time. I generally use 64M-512M, depending on the space of the server. innodb_log_buffer_size
The default value is fine for most applications with medium write operations and short transactions. If you update frequently or use a lot of blob data, you should increase this value. But if it is too large, it is also a waste of memory, because it will always flush (how do you say this word in Chinese?) once every second, so there is no need to set it to more than 1 second. 8M-16M should generally be enough. Small applications can be set smaller. innodb_flush_log_at_trx_commit##Complaining that Innodb is 100 times slower than MyISAM? Then you probably forgot to adjust this value. The default value of 1 means that every transaction commit or instruction outside the transaction needs to write the log to the hard disk (flush), which is very time-consuming. Especially when using battery backed up cache. Setting it to 2 is fine for many applications, especially those transferred from MyISAM tables. It means not writing to the hard disk but writing to the system cache. The logs are still flushed to disk every second, so you generally won't lose more than 1-2 seconds of updates. Setting it to 0 will be faster, but the security is poor. Even if MySQL hangs up, transaction data may be lost. while a value of 2 will only work across the entire operating system
Data may be lost only when it hangs.
This article explains the relevant introduction about mysql optimization insert performance. For more information, please pay attention to the PHP Chinese website.
How to use php Commonly used custom methods
How to use XOR encryption through php /Decrypt file
How to get the name of a variable through php
The above is the detailed content of Relevant introduction to mysql optimization insert performance. For more information, please follow other related articles on the PHP Chinese website!

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

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 key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

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.
