mysql如何快速生成测试大数据库

快速生成1000W测试数据库;

创建测试表:

sql 复制代码
create table user (  
    id int(10) not null auto_increment,   
    uname  varchar(20) ,  
    regtime  char(30)  ,  
    age  int(11)   ,
    primary key (id)
)  
engine=myisam default charset=utf8 collate=utf8_general_ci  ,
auto_increment=1 ;

编写存储过程:

sql 复制代码
delimiter $$
SET AUTOCOMMIT = 0$$
 
create  procedure test()
begin
declare v_cnt decimal (10)  default 0 ;
dd:loop
          insert  into user values
    (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50),
        (null,rand()*10,now(),rand()*50);
      commit;
        set v_cnt = v_cnt+10 ;
           if  v_cnt = 10000000 then leave dd;
          end if;
         end loop dd ;
end;$$
 
delimiter ;

调用存储过程:

sql 复制代码
call test();
相关推荐
難釋懷6 分钟前
Redis数据结构介绍
数据结构·数据库·redis
松涛和鸣9 分钟前
54、DS18B20单线数字温度采集
linux·服务器·c语言·开发语言·数据库
哟哟耶耶16 分钟前
java-MySql下载与配置环境变量
java·开发语言·mysql
码农胖虎-java21 分钟前
【高频面试题】MySQL高频面试&实战:慢查询排查+索引底层(B+树/联合索引)全解析
b树·mysql·面试
indexsunny26 分钟前
互联网大厂Java面试实战:核心技术与微服务架构解析
java·数据库·spring boot·缓存·微服务·面试·消息队列
合方圆~小文29 分钟前
三目智能监控新标杆
数据库·人工智能·模块测试
神秘的猪头30 分钟前
AI全栈项目 Day 3:不仅是数据库,更是你的“数据堡垒” —— PostgreSQL 硬核入门
数据库·sql·postgresql
天人合一peng34 分钟前
kingbase数据库的
服务器·数据库·oracle
雨季66636 分钟前
系统化方法论与实战案例
数据库
数据库知识分享者小北41 分钟前
从极速复制“死了么”APP,看AI编程时代的技术选型
数据库·阿里云·状态模式·ai编程·supabase