mysql 為測試資料庫填充大量資料

2021-09-02 16:01:33 字數 1419 閱讀 3823

首先建立乙個庫

create database mysqlsystems

use mysqlsystems;

建立兩個表 - innodb的和myisam的

create table `myisam` (

`id` int(11) not null auto_increment,

`name` varchar(50) default null,

`post` text,

primary key (`id`)

) engine=myisam default charset=utf8;

create table `innodb` (

`id` int(11) not null auto_increment,

`name` varchar(50) default null,

`post` text,

primary key (`id`)

) engine=innodb default charset=utf8;

這樣叫建立了兩個表,innodb和myisam。

建立可插入資料的 儲存過程

delimiter @

create procedure insert_isam(in item integer)

begin

declare counter int;

set counter = item;

while counter >= 1 do

insert into myisam values(counter,concat('mysqlsystems.com',counter),repeat('bla',10));

set counter = counter - 1;

end while;

end@

create procedure insert_innodb(in item integer)

begin

declare counter int;

set counter = item;

while counter >= 1 do

insert into innodb values(counter,concat('mysqlsystems.com',counter),repeat('bla',10));

set counter = counter - 1;

end while;

end@

delimiter ;

好了,執行吧,

你要插入100條到innodb?         執行call insert_innodb(100)

插入1000000到myisam?          call insert_myisam(1000000)

記得再一次插入新的內容時,要清空你的表,delete from ,或者truncate 。

mysql造大量測試資料

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

mysql迴圈插入大量測試資料

最近業務場景的需要,mysql單錶要插入大量資料,考慮到單條記錄長短對資料儲存量有很大的影響,所以進行了一次插入檢索測試。插入 procedure delimiter drop procedure if exists insert current data uuid create procedure...

構造大量測試資料的方法(MySql)

建立測試表 create table sys user id char 32 not null default comment 主鍵 username varchar 100 not null default comment 使用者名稱 password char 32 not null defau...