Mysql数据库导入千万条数据
程序员文章站
2022-04-11 16:11:45
...
第一步 创建数据库
sql语句:
CREATE DATABASE aaaa
第二步 创建表
sql语句:
CREATE TABLE usertb(
id serial,
uname varchar(20) ,
ucreatetime datetime ,
age int(11))
ENGINE=MYISAM
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=1
ROW_FORMAT=COMPACT;
第三步 创建插入数据存储过程
sql语句:
DELIMITER $$
SET AUTOCOMMIT = 0$$
CREATE PROCEDURE test1()
BEGIN
DECLARE v_cnt DECIMAL (10) DEFAULT 0 ;
dd:LOOP
INSERT INTO usertb VALUES
(NULL,'用户1','2010-01-01 00:00:00',20),
(NULL,'用户2','2010-01-01 00:00:00',20),
(NULL,'用户3','2010-01-01 00:00:00',20),
(NULL,'用户4','2010-01-01 00:00:00',20),
(NULL,'用户5','2011-01-01 00:00:00',20),
(NULL,'用户6','2011-01-01 00:00:00',20),
(NULL,'用户7','2011-01-01 00:00:00',20),
(NULL,'用户8','2012-01-01 00:00:00',20),
(NULL,'用户9','2012-01-01 00:00:00',20),
(NULL,'用户0','2012-01-01 00:00:00',20)
;
COMMIT;
SET v_cnt = v_cnt+10 ;
IF v_cnt = 10000000 THEN LEAVE dd;
END IF;
END LOOP dd ;
END;$$
DELIMITER ;
第四步 执行存储过程
执行sql语句
call test1;