Five tips for optimizing the MySQL Insertion Method

Source: Internet
Author: User

The following are five ways to improve the query of inserted tables:

1) using load data infile to download DATA from text is 20 times faster than using the insert statement.

2) INSERT several rows at a time using an INSERT statement with multiple VALUES lists, which is several times faster than using a single row INSERT statement. Adjusting the bulk_insert_buffer_size variable can also increase the insert speed (to a table containing rows.

3) The system variable Concurrent_insert can be inserted to the myisam table in parallel and can be set to modify the concurrent-insert Process. This variable is set to 1 by default. If concurrent_insert is set to 0, parallel insert is disabled. If this variable is set to 2, it can be inserted at the end of the table in parallel, even if some rows of the table have been deleted.

4) Insert latency

This is useful if your customers cannot or do not have to wait until the insertion is complete. When you use MySQL to store and regularly run SELECT and UPDATE statements that take a long time to complete, you will find this situation very common. When the customer uses the insert delay, the server immediately returns the result. If the table is not called by other threads, the row will wait for the table to be inserted. Another advantage of using insert latency is that insertion from multiple customers is bound and recorded in the same block. This is much faster than processing multiple independent inserts.

5) Lock the table before insertion (only for non-transactional tables)

This will improve the database performance, because the index buffer only refresh the disk after all the insert statements are completed. Under normal circumstances, the index buffer refresh will occur as many insert statements as possible. If you can use an insert statement to insert all rows, you do not need to use an explicit lock statement.

To insert a TRANSACTION table more quickly, use the start transaction and COMMIT statements instead of the lock tables statement.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.