MySQL creates 100W of data with stored procedures

Source: Internet
Author: User

Title

1.100W data insertion, define while loop to execute 100W times from the 1-100w,insert statement, run from 11 o'clock to 10 in the morning of the next day, a total of 11 hours!!!

1 DELIMITER $$2 3DROP PROCEDUREIFEXISTS ' Havefun '.' Create_100w_data ' $$4 5 CREATE6     /*[definer = {User | Current_User}]*/7PROCEDURE ' Havefun '.' Create_100w_data ' ()8     /*LANGUAGE SQL9     | [NOT] DeterministicTen     | {CONTAINS SQL | NO SQL | READS SQL DATA | Modifies SQL DATA} One     | SQL SECURITY {definer | INVOKER} A     | COMMENT ' String '*/ - BEGIN -     DECLAREi INT; theDROP TABLEIFEXISTS ' Havefun '.' 100w_data '; - CREATE TABLE ' 100w_data ' ( -' ID ' INT (TEN) UNSIGNED notNULLAuto_increment COMMENT ' master ID ', -' Name ' CHAR (NO)NULL DEFAULT' COMMENT ' name ', +' Status ' INT (1) UNSIGNED notNULL DEFAULT' COMMENT ' status, 1-approved by 0-failed 99-pending review ', -' Type ' VARCHAR (not)NULL DEFAULT' COMMENT ' type ', +PRIMARYKEY(' id ') A) Engine=innodbDEFAULTcharset=UTF8; at  -SET I=1; -      while(i<1000000) Do -INSERT into ' 100w_data ' (' Name ', ' status ', ' type ') VALUES (CONCAT (' Data_ ', i), ' a ', ' PROC '); -SET i=i+1; -     END  while; in  -     END$$ to  +DELIMITER;

2. Define the start and end points of the insertion so that the stored procedure can be executed in multiple processes to increase the rate. (You can also run with PHP scripts)

1 DELIMITER $$2 3  Use' Havefun ' $$4 5DROP PROCEDUREIFEXISTS ' create_i_data ' $$6 7CREATE definer= ' root ' @ '% ' PROCEDURE ' create_i_data ' (in _start INT,In _end INT)8 BEGIN9     DECLAREi INT;TenDROP TABLEIFEXISTS ' Havefun '.' Amt_data '; One CREATE TABLE ' Amt_data ' ( A' ID ' INT (TEN) UNSIGNED notNULLAuto_increment COMMENT ' master ID ', -' Name ' CHAR (NO)NULL DEFAULT' COMMENT ' name ', -' Status ' INT (1) UNSIGNED notNULL DEFAULT' COMMENT ' status, 1-approved by 0-failed 99-pending review ', the' Type ' VARCHAR (not)NULL DEFAULT' COMMENT ' type ', -' Create_time ' TIMESTAMP notNULL DEFAULTCurrent_timestamp on UPDATE current_timestamp COMMENT ' creation time ', -' Update_time ' INT (one) notNULLCOMMENT ' Update Time ', -PRIMARYKEY(' id ') +) Engine=innodbDEFAULTcharset=UTF8; -SET i=_start; +      while(I<_end) Do AINSERT into ' amt_data ' (' Name ', ' status ', ' type ', ' create_time ', ' Update_time ') VALUES (CONCAT (' Data_ ', i), ' a ', ' PROC ', Now (),Unix_timestamp (now ())); atSET i=i+1; -     END  while; -     END$$ -  -DELIMITER;

MySQL creates 100W of data with stored procedures

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.