Optimization of the Mysql INSERT statement

Source: Internet
Author: User
Tags bulk insert mysql insert

1) If you insert many rows from the same customer at the same time, use the INSERT statement for multiple value tables. This is faster than using separate INSERT statements (several times in some cases).
Insert into test values (1,3), (1,4) ...

2) If you insert many rows from different customers, you can get a higher speed by using the Insert delayed statement. The implication of delayed is that the INSERT statement executes immediately, but the data is placed in the queue of memory and is not actually written to the disk, which is much faster than inserting each statement, and Low_priority just the opposite, when all other users have finished reading and writing the table.

3) Place index files and data files on separate disks (using the options in the Build table).

4) If BULK INSERT, you can increase the value of the bulk_insert_buffer_size variable to increase the speed, however, this can only be used for the MyISAM table.

5) When loading a table from a text file, use load DATA INFILE. This is usually 20 times times faster than using many INSERT statements.

6) Use the Replace statement instead of INSERT, depending on the application.

7) Use the Ignore keyword to ignore duplicate records, depending on your application.
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.