MySQL using stored procedures insert batch testing data

One of scenarios: Sometimes, we need to create a table and fill a large number of test data.

Methods as below:

Let's create a new table, create two general index.
TABLE `the IF the NOT EXISTS the CREATE t` (
  ` id` int (. 11) the NOT NULL,
  `a` int (. 11) the DEFAULT NULL,
  ` B` int (. 11) the DEFAULT NULL,
  a PRIMARY KEY ( `id`),
  KEY` A `(` a`),
  KEY `B` (` B`)
) = the InnoDB ENGINE;


 Here we use a stored procedure to insert table 10w test data, if mysql stored procedures are not familiar, see my comments in the code, should be able to see to understand.
# Define segmentation symbol, mysql default delimiter is a semicolon; defined here as //
# delimiter main function is to tell mysql to meet next // sign that the implementation of the whole of the above sql statement
delimiter //

# Create a stored procedure named testData
the Create Procedure testData ()

# This is represented by the following cycle of data into the table 10w insert
the begin
  DECLARE I int;
  SET = I. 1;
  the while (I <= 100000) do
    INSERT INTO T values (I, I, I);
    SET +. 1 I = I ;
  End the while;
End encountered here // // # symbol, namely the implementation of a whole paragraph above sql statement

delimiter; # mysql separator is restored;

call testData (); # call a stored procedure


Data insertion is completed! Note:'ll need on a personal development machine a long time, is expected to about 15 minutes [PC]

Guess you like

Origin www.linuxidc.com/Linux/2019-08/160323.htm