mysql 批量插入百萬測試資料

2021-10-18 22:58:33 字數 2399 閱讀 2383

最近複習mysql索引相關效能,需要大批量資料進行測試,記個筆記;

create table `user_test` (

`user_id` bigint(20

) not null auto_increment comment '使用者id'

, `login_name` varchar(30

) not null comment '登入賬號'

, `email` varchar(50

) default '' comment '使用者郵箱'

, `phonenumber` varchar(11

) default '' comment '手機號碼'

, `***` char(1

) default '0' comment '使用者性別(0男 1女 2未知)'

, `password` varchar(50

) default '' comment '密碼'

, `create_time` datetime default current_timestamp comment '建立時間'

, `update_time` datetime default current_timestamp on update current_timestamp comment '更新時間'

, primary key (`user_id`)

) engine=innodb auto_increment=

1000102 default charset=utf8mb4 comment=

'測試'

-- 插入100000條資料

delimiter $$

drop function if exists `test_fun`$$

create function `test_fun`(

) returns int(11

)begin

declare num int default 1000000

; declare i int default 0

; while i-- 插入語句

insert into user_test

(`login_name`,`email`,`phonenumber`,`***`,`password`)

values

(concat

('使用者'

,i),

concat

(floor

(rand()

*((999999

-111111)+

111111))

,'@qq.com'),

concat

('135'

,floor

(rand()

*((99999999

-11111111)+

11111111))

),floor

(rand()

*2),

uuid()

);set i = i+1;

end while;

return i;

end$$

delimiter ;

-- 執行函式

select test_fun()

;

delimiter $$

drop procedure if exists `test_proc`$$

create procedure `test_proc`(

)begin

declare num int default 1000000

; declare i int default 1

; while iinsert into user_test

(`login_name`,`email`,`phonenumber`,`***`,`password`)

values

(concat

('使用者'

,i),

concat

(floor

(rand()

*((999999

-111111)+

111111))

,'@qq.com'),

concat

('135'

,floor

(rand()

*((99999999

-11111111)+

11111111))

),floor

(rand()

*2),

uuid()

);set i = i+1;

end while;

end$$

delimiter ;

call test_proc()

;

MYSQL 插入百萬測試資料

1.建表 drop table if exists test user create table test user id int auto increment,name varchar 50 gender tinyint,addr varchar 100 primary key id engine...

MYSQL 插入百萬測試資料

適用場景 mysql5.7 1.建表 drop table if exists test user create table test user id int auto increment name varchar 50 gender tinyint addr varchar 100 primary...

MySQL批量插入測試資料

mysql批量插入測試資料。在開發過程,經常需要在資料庫中生成大量的測試資料,這個時候,我們可以使用儲存過程幫我們完成這項工作。首先,我們建立一張測試表,例如t user create table t user id bigint 20 not null auto increment,name va...