How does MySQL rapidly insert large amounts of data?

Source: Internet
Author: User

How to quickly insert a large amount of data in MySQL these days have tried to use different storage engines to insert a large number of MySQL table data, mainly testing the MyISAM storage engine and InnoDB.
The following is an experiment: www.2cto.com I. InnoDB Storage engine. Create database ecommerce; create table employees (id int not null, fname VARCHAR (30), lname VARCHAR (30), birth TIMESTAMP, hired date not null default '2017-01-01 ', separated date not null default '2017-12-31', job_code int not null, store_id int not null) partition by range (store_id) (partition p0 values less than (10000), partition p1 values less than (50000), partition p2 values less than (100000), partition p3 values less than (150000 ), partition p4 values less than maxvalue); www.2cto.com CREATE the Stored PROCEDURE SQL code use ecommerce; CREATE PROCEDURE BatchInsert (IN init INT, IN loop_time INT) BEGIN DECLARE Var INT; DECLARE ID INT; SET Var = 0; set id = init; WHILE Var <loop_time DO insert into employees (id, fname, lname, birth, hired, separated, job_code, store_id) values (ID, CONCAT ('chen', ID), CONCAT ('haixiang ', ID), Now (), 1, ID ); set id = ID + 1; SET Var = Var + 1; end while; END; when calling the stored procedure to insert data SQL code CALL BatchInsert: 3 h 37 min 8sec 2. MyISAM storage engine create table SQL code use ecommerce; CREATE TABLE ecommerce. customer (id int not null, email VARCHAR (64) not null, name VARCHAR (32) not null, password VARCHAR (32) not null, phone VARCHAR (13), birth DATE, sex INT (1), avatar BLOB, address VARCHAR (64), regtime DATETIME, lastip VARCHAR (15), modifytime timestamp not null, primary key (id )) ENGINE = MyISAM ROW_FORMAT = DEFAULT partition by range (id) (partition p0 values less than (100000), partition p1 values less than (500000), partition p2 values less than (1000000 ), partition p3 values less than (1500000), partition p4 values less than (2000000), Partition p5 values less than maxvalue); Create a Stored PROCEDURE SQL code use ecommerce; DROP PROCEDURE IF EXISTS ecommerce. batchInsertCustomer; create procedure BatchInsertCustomer (IN start INT, IN loop_time INT) begin declare Var INT; declare id int; SET Var = 0; set id = start; WHILE Var <loop_time DO insert into customer (ID, email, name, password, phone, birth, sex, avatar, address, regtime, lastip, modifytime) values (ID, CONCAT (ID, '@ sina.com'), CONCAT ('name _ ', rand (ID) * 10000 mod 200), 123456,13800000000, adddate ('2017-01-01 ', (rand (ID) * 36520) mod 3652), Var % 2 ,' http://t3.baidu.com/it/u=2267714161,58787848&fm=52&gp=0.jpg ', 'Haidian district, Beijing', adddate ('1970-01-01', (rand (ID) * 1995) mod 36520), '8. 8.8.8 ', adddate ('1970-01-01', (rand (ID)
* 36520) mod 3652); SET Var = Var + 1; set id = ID + 1; end while; END; call the SQL code ALTER TABLE customer DISABLE KEYS for inserting data in the stored procedure; CALL BatchInsertCustomer (); alter table customer enable keys; time: 8 min 50 sec through the comparison above, we found that the MyISAM storage engine can be used to insert a large amount of data, if you need to modify MySQL Storage
The ENGINE can use the command: SQL code ALTER TABLE t ENGINE = MYISAM;

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.