MySQL BULK INSERT data

Source: Internet
Author: User
Tags bulk insert types of tables

MySQL BULK INSERT data

1. For MyISAM types of tables, you can quickly import large amounts of data in the following ways.

ALTER TABLE tblname DISABLE KEYS;

Loading the data

ALTER TABLE tblname ENABLE KEYS;

These two commands are used to open or close an update for a non-unique index of the MyISAM table. When importing large amounts of data into a non-empty MyISAM table, you can increase the efficiency of the import by setting these two commands. For importing large amounts of data into an empty MyISAM table, the default is to import the data first and then create the index, so you don't have to set it up.

2. For InnoDB types of tables, this approach does not improve the efficiency of importing data. For InnoDB types of tables, there are several ways we can improve the efficiency of the import:

A. Because tables of the InnoDB type are saved in the order of the primary key, the imported data is arranged in the order of the primary key, which effectively improves the efficiency of the imported data. If the InnoDB table does not have a primary key, an internal column is created by default as the primary key, so if you can create a primary key for the table, you can use this advantage to improve the efficiency of importing data.

B. Perform set unique_checks=0 before importing data, turn off uniqueness Check, execute set unique_checks=1 after import, restore uniqueness check, can improve efficiency of import.

C. If the app uses autocommit, it is recommended to execute set autocommit=0 before import, turn off autocommit, and then execute after import.

Reference: http://cdbit.com/read/insert-large-data-to-mysql.html

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.