• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
tmdba---timmy的dba记录
技术创造生活
博客园    首页    新随笔    联系   管理    订阅  订阅
随机生成mysql测试表大量数据

有时候为了测试mysql性能,需要生产一张上万,百万,千万的表,有如下方法可实现

 

 SET GLOBAL log_bin_trust_function_creators = 1;

create function rn()
returns smallint
begin
declare res smallint default 0;
set res=floor(1+rand()*3000) ; #这里1和3000的位置可以更改为你需要的范围。
return res;
end




create function rs(n int)
returns varchar(1024)
begin
declare chars char(52) default 'abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ';
declare res varchar(1024) default '';
declare i int default 0;
repeat
set i = i + 1;
set res = concat(res,substring(chars,floor(1+rand()*52),1));
until i=n end repeat;
return res;
end


create procedure inst(n int)
begin
declare i int default 0;
set autocommit = 0;
repeat
set i = i + 1;
insert into jc_user_kw (user_id,kw_name,kw_price) values(10,rs(10),rn()); -----jc_user_kw 为表名,其他为列名
until i=n  end repeat;
commit;
set autocommit = 1;
end

call inst(10000)
posted on 2017-02-26 15:53  tmdba  阅读(3254)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3