zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

MySQL数据库创建随机测试数据

mysql数据库 创建 随机 测试数据
2023-09-27 14:28:38 时间

(1)创建测试表

create table test01
(
id1 int not null auto_increment,
name varchar(30),
primary key(id1)
);

create table test02
(
id2 int not null auto_increment,
name varchar(30),
primary key(id2)
);

 

(2)创建存储过程

CREATE DEFINER=`root`@`%` PROCEDURE `p_insert`()
BEGIN
#Routine body goes here...
DECLARE str1 varchar(30);
DECLARE str2 varchar(30);
DECLARE i int;
set i = 0;

while i < 10000 do
set str1 = substring(md5(rand()),1,25);
insert into test01(name) values(str1);
set str2 = substring(md5(rand()),1,25);
insert into test02(name) values(str2);
set i = i + 1;
end while;
END

 

(3)制定定时事件

use lijiamandb;
create event if not exists e_insert
on schedule every 10 second
on completion preserve
do call p_insert();

 


(4)手动开始event

mysql> show variables like '%event_scheduler%';
+----------------------------------------------------------+-------+
| Variable_name | Value |
+----------------------------------------------------------+-------+
| event_scheduler | OFF |
+----------------------------------------------------------+-------+

mysql> set global event_scheduler = on;
Query OK, 0 rows affected (0.08 sec)

 

 

其它测试数据:

https://github.com/datacharmer/test_db

 

 

 

 

 

相关文档集合:

1.MySQL数据库创建随机测试数据
2.Oracle数据库创建随机测试数据