searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

使用SQL脚本插入大量mysql数据

2023-05-22 00:55:14
31
0

先建立数据库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
0条评论
0 / 1000
cennjing
3文章数
0粉丝数
cennjing
3 文章 | 0 粉丝
cennjing
3文章数
0粉丝数
cennjing
3 文章 | 0 粉丝
原创

使用SQL脚本插入大量mysql数据

2023-05-22 00:55:14
31
0

先建立数据库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
文章来自个人专栏
sss
1 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0