先建立数据库db_test和数据表mytest_1000w。
create database db_test;
CREATE TABLE mytest_1000w(
my_id INT,
str_1 VARCHAR(128) NOT NULL,
str_2 VARCHAR(128) NOT NULL,
str_3 VARCHAR(128) NOT NULL,
str_4 VARCHAR(128) NOT NULL,
str_5 VARCHAR(128) NOT NULL,
str_6 VARCHAR(128) NOT NULL,
str_7 VARCHAR(128) NOT NULL,
str_8 VARCHAR(128) NOT NULL,
str_9 VARCHAR(128) NOT NULL,
str_10 VARCHAR(128) NOT NULL,
str_11 VARCHAR(128) NOT NULL,
str_12 VARCHAR(128) NOT NULL,
str_13 VARCHAR(128) NOT NULL,
str_14 VARCHAR(128) NOT NULL,
str_15 VARCHAR(128) NOT NULL,
str_16 VARCHAR(128) NOT NULL,
str_17 VARCHAR(128) NOT NULL,
str_18 VARCHAR(128) NOT NULL,
str_19 VARCHAR(128) NOT NULL,
str_20 VARCHAR(128) NOT NULL,
PRIMARY KEY(my_id)
);
建立testInsert.sql文件:
DELIMITER //
DROP PROCEDURE if exists testInsert;
CREATE PROCEDURE testInsert()
BEGIN
DECLARE str VARCHAR(255);
DECLARE num int;
SET str = "";
SET num = 0;
WHILE
num < 10000000 DO
SET str = CONCAT('aaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbbaaaaaaaaaa',num);
INSERT INTO mytest_1000w (my_id,str_1,str_2,str_3,str_4,str_5,str_6,str_7,str_8,str_9,str_10,str_11,str_12,str_13,str_14,str_15,str_16,str_17,str_18,str_19,str_20)
VALUES
(num,str,str,str,str,str,str,str,str,str,str,str,str,str,str,str,str,str,str,str,str);
SET num = num + 1;
END WHILE;
END//
CALL testInsert();
用mysql客户端导入数据:
mysql -uroot -P3306 -h127.0.0.1 -pxxx -Ddb_test<testInsert.sql