Mysql 儲存過程造測試資料

2022-03-03 04:32:47 字數 1627 閱讀 8194

1.mysql 儲存過程造測試資料

--

建立乙個使用者表

create

table

`sys_user` (

--`id` char (32) not null default '' comment '主鍵',

`id` int(11) not

null auto_increment comment '主鍵'

, `username`

varchar (100) not

null

default

'' comment '

使用者名稱'

, `password`

char (32) not

null

default

'' comment '密碼'

, `status`

tinyint (1) not

null

default'0

' comment '狀態'

, `desz`

varchar (200) default

null comment '描述'

,

primary

key(`id`)

) engine

= innodb default charset = utf8 comment =

'使用者表'--

建立儲存過程 名稱:myproc

create

procedure myproc (in total int

)begin

declare v int

;set v =1;

--開啟事務

start transaction

;while v <=

total do

insert

into

sys_user (

--id,

username,

password,

status,

desz

)values

(

--replace (uuid(), '-', ''),

concat(

'使用者-

', v),

concat(

'pwd-

', v),

v %2

, concat(

'描述-

', v)

) ;set v = v +1;

endwhile;--

提交事務

commit

;end;--

檢視當前建立的儲存過程

show procedure

status;

--設定自增初始值

alter

table sys_user auto_increment=1--

執行儲存過程,傳入引數

call myproc(5500000

);--

刪除儲存過程

drop

procedure myproc;

測試100萬條耗時60s

測試550完條耗時362.679s

mysql造大量測試資料

我們在進行測試時候,有時候需要造大量的測試資料,但是資料庫對於大量資料的插入和刪除很耗時間。1.首先實現自動化 肯定想到的是儲存過程 現在利用工具寫儲存過程很方便,框架都搭好了,填填邏輯就好 2.資料插入 利用批量插入 我試了一下,插了30萬資料14.042s的速度還是很快的 3.資料刪除 最好是直...

mysql儲存過程,生成測試資料

指定要插入資料的表,如 tb info表 建立記憶體表,可以增加插入效率 create tb info memory delimiter 修改mysql delimiter drop procedure ifexists add data create procedure add data in n...

mysql儲存過程,作測試資料使用

小弟在此僅作測試用,所以簡單建了個表 1.表結構 create table t user username varchar 50 default null,userpassword varchar 50 default null engine innodb default charset utf8 ...