1,创建表

id name sex phone birthplace grade
唯一、自增 姓名 性别 11位手机号、唯一 籍贯 年级
create table student(id int(4) primary key not null auto_increment,name varchar(32) not null,sex varchar(2) not null,phone varchar(32) not null unique,brithplace varchar(32) not null,grade int(1) not null
);

2,创建函数

编写生成电话号码的函数:

DELIMITER $$
create function generate_phone()
returns varchar(11)
begindeclare phone varchar(11) default "1";    declare i int default 0; set phone = concat(phone, elt(ceiling((rand()*10))%4+1,"3","5","7","8"));    while i < 9doset phone = concat(phone, elt(ceiling((rand()*10)),"0","1","2","3","4","5","6","7","8","9"));set i = i + 1;end while; return phone;
end ;$$
DELIMITER ;

随机生成年级的函数:

DELIMITER $$
create function generate_grade()
returns int(1)
beginreturn ceiling((rand()*10))%9+1;
end $$
DELIMITER ;

随机生成性别的函数:

DELIMITER $$
create function generate_sex()
returns varchar(2)
beginreturn elt(ceiling(rand()*2), "男","女");
end $$
DELIMITER ;

随机生成出生地的函数:

DELIMITER $$
create function generate_brithplace()
returns varchar(32)
beginreturn  elt(ceiling(rand()*100)%34+1,"河北省","山西省","辽宁省","吉林省","黑龙省","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","海南省","四川省","贵州省 ","云南省","陕西省","甘肃省","青海省","台湾省","北京市","上海市","重庆市","天津市","广西","宁夏","西藏","新疆","内蒙古","香港","澳门");
end $$
DELIMITER ;

随机生成男孩名字的函数:

DELIMITER $$
create function generate_boyname() returns varchar(2)
begindeclare name varchar(2) default '';declare i int default 0;declare n int default 0;    set n = ceiling(rand()*2);    while i < ndoset name = concat(name, elt(ceiling(rand()*1000)%200+1,"辰","逸","雨","泽","瑾","瑜","圣","杰","楷","瑞","浩","南","卡","思","旭","尧","俊","楠","天","磊","烨","伟","世","博","昊","哲","瀚","冠","明","辉","金","傲","越","材","霖","朋","健","柏","鸿","涛","懿","轩","鹏","煊","彬","益","弘","宸","苑","君","文","鑫","睿","渊","达","强","晓","啸","风","桦","驰","松","德","振","豪","鹤","绍","鼎","寒","志","靖","琪","擎","宇","国","龙","厉","诚","翰","超","晟","棋","沙","欧","智","劲","祺","皓","新","泰","佑","致","韵","舟","玮","伦","然","炫","星","野","雪","嘉","煜","城","昌","建","平","炎","峻","熙","洋","荣","展","远","图","翱","依","海","震","康","锋","崇","杭","运","贤","元","盛","江","春","凯","胜","福","来","聚","原","才","邦","庆","生","月","阳","岩","浪","晋","玄","欢","恒","羽","恩","青","余","波","修","永","润","若","信","勋","琦","晨","杉","畅","凡","翎","承","淘","茂","石","鉴","尚","唯","仁","敬","玉","全","帆","影","云","观","雷","常","柯","倚","向","镇","言","耀","耿","古","闻","名","东","悠","昆","宝","复","乔","柳","林","均"));set i = i + 1;end while;return name;
end ; $$
DELIMITER ;

随机生成一个女孩的名字:

DELIMITER $$
create function generate_girlname() returns varchar(2)
begindeclare name varchar(2) default '';declare i int default 0;declare n int default 0;    set n = ceiling(rand()*2);    while i < ndoset name = concat(name, elt(ceiling(rand()*1000)%200+1,"静","敏","燕","艳","丽","娟","莉","芳","萍","玲","娜","丹","洁","红","颖","琳","霞","婷","慧","莹","晶","华","倩","英","佳","梅","雪","蕾","琴","璐","伟","云","蓉","青","薇","欣","琼","宁","平","媛","虹","杰","婧","雯","茜","楠","洋","君","辉","菲","琦","妍","阳","波","俊","鑫","磊","军","爽","兰","晨","冰","瑶","瑾","岩","瑛","悦","群","玮","欢","瑜","蕊","宇","明","珊","荣","超","琪","玉","怡","文","岚","杨","婕","旭","凤","健","芬","芸","晓","萌","飞","露","菁","惠","宏","瑞","蓓","林","璇","珍","月","利","勤","清","帆","迪","微","斌","娇","影","巍","朋","莎","彬","峰","昕","乐","星","新","烨","晖","卉","晴","曼","越","靖","维","晔","艺","睿","芹","淼","黎","畅","椒","鹏","春","彦","柳","梦","毅","妮","坤","翠","然","钰","蔚","曦","茹","凌","扬","凡","美","彤","园","炜","捷","亮","叶","苗","菊","勇","锐","雨","力","翔","庆","方","琰","聪","潇","威","甜","帅","进","琛","花","雅","立","姣","馨","珏","秀","亚","珂","思","哲","冉","骊","双","娅","胡","培","斐","嘉","莲","莺","佩","剑"));set i = i + 1;end while;return name;
end ; $$
DELIMITER ;

根据性别随机生成一个姓名:

DELIMITER $$
create function generate_name(sex varchar(2))
returns varchar(3)
begindeclare firstname varchar(2) default '';declare lastname varchar(2) default '';    set firstname = elt(ceiling(rand()*1000)%200+1,"赵","钱","孙","李","周","吴","郑","王","冯","陈","卫","蒋","沈","韩","杨","朱","秦","尤","许","何","吕","施","张","孔","曹","严","华","金","魏","陶","姜","戚","谢","邹","喻","柏","水","窦","章","云","苏","潘","葛","范","彭","郎","鲁","韦","昌","马","苗","凤","花","方","俞","任","袁","柳","鲍","史","唐","费","廉","岑","薛","雷","贺","倪","汤","滕","殷","罗","毕","郝","邬","安","常","乐","于","时","傅","皮","卞","齐","康","伍","余","元","卜","顾","孟","平","黄","和","穆","萧","尹","姚","邵","湛","汪","祁","毛","禹","狄","米","贝","明","臧","计","伏","成","戴","谈","宋","茅","庞","熊","纪","舒","屈","项","祝","董","梁","杜","阮","蓝","席","季","麻","强","贾","路","娄","危","江","童","颜","郭","梅","盛","林","刁","钟","徐","邱","骆","高","夏","蔡","田","樊","胡","凌","霍","虞","万","支","柯","昝","管","卢","莫","经","房","裘","缪","干","解","应","宗","丁","宣","贲","邓","郁","单","杭","洪","包","诸","左","石","崔","吉","钮","龚","程","嵇","邢","滑","裴","陆","荣","翁","荀","羊","於","惠");if ( sex = "男" ) thenset lastname = generate_boyname();    elseset lastname = generate_girlname();   end if;return concat(firstname, lastname);
end $$
DELIMITER ;

3,编写过程:

DELIMITER @
create procedure proc_data (in total int)
begin
declare i int default 1;
declare phone varchar(32);
declare sex varchar(2);
declare continue handler for 1062
beginselect concat(i) "count", concat("phone ", phone, " alrady exist") "info"; set i = i - 1 ;
end;
while i <= total doset phone = generate_phone();set sex = generate_sex();insert into student(name, sex, phone, brithplace, grade) values(generate_name(sex), sex, phone, generate_brithplace(), generategrade());set i = i + 1 ;
end while;
end;@
DELIMITER ;

mysql模拟大量数据相关推荐

  1. 数据可视化 数据可视化看板项目一:(1)模拟实时数据 -使用MYSQL的事件建立动态模拟数据,每秒更新一次 (1)

    需求: 市场人员进行数据可视化产品销售公关时,一定会遇到一个问题,就是客户要求进行展示. 但是我们不可能透露其它客户目前的真实实时更新的数据. 那么这里就要求,创建模拟的秒级别的数据. 方法: 1.使 ...

  2. mysql 存储过程 生成数据_mysql使用存储过程,批量生成测试数据

    1.存储过程代码 delimiter $$ DROP PROCEDURE IF EXISTS create_service_data$$ create procedure create_service ...

  3. Canal 实现 Mysql数据库实时数据同步

    简介 1.1 canal介绍 Canal是一个基于MySQL二进制日志的高性能数据同步系统.Canal广泛用于阿里巴巴集团(包括https://www.taobao.com),以提供可靠的低延迟增量数 ...

  4. MySQL异构同步_详解MySQL数据库异构数据同步

    本文主要向大家介绍了MySQL数据库异构数据同步,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 在实现levelDB挂载成MySQL引擎时,发现在实际存储是key-value格式 ...

  5. 模拟购物数据实时流处理(4)——实时数据大屏

    项目介绍 本项目总体分为 平台搭建 模拟数据源生成 实时流数据处理 实时数据大屏 这几个部分,我将分成几个博客分别介绍这些部分的工作,本文主要介绍最后一个部分,实时数据大屏. 前面的几篇文章已经将平台 ...

  6. 分布式日志sleuth+分布式追踪系统zipkin+消息中间件rabbitMQ+MySQL存储跟踪数据

    一.了解分布式架构下系统的监控问题 接口监控问题 监测性能瓶颈 解决方案:Sleuth 日志监控问题 日志分散 解决方案:ELK+Kafka 二.使用Sleuth实现大觅网微服务跟踪 1.打开一个分布 ...

  7. MySQL多行数据合并(单例显示多个值)之GROUP_CONCAT()函数(字符串连接函数)

    MySQL多行数据合并之GROUP_CONCAT函数 一.GROUP_CONCAT函数语法 二.创建表和添加测试数据 1.建表 2.添加测试数据 三.编写测试SQL语句 1.人员信息表(左)和房间信息 ...

  8. MySql下大数据量级别(1000万+)优化查询和操作方法

    MySql下大数据量级别(1000万+)优化查询和操作方法 一.[原则一]: insert into tb (...) values(...),(...)...; 要比 insert into tb ...

  9. 基于Canal的MySQL=>ES数据同步方案

    文章目录 1.MySQL和ES的主要区别? 1.1 功能性 1.2 性能指标 1.3 在搜索业务上的区别 1.3.1 查询 1.3.2 检索 2.为什么要做数据同步 2.1 检索性能 2.2 写入性能 ...

  10. MySQL之误删数据如何处理

    写在前面 在工作中不管是程序bug,运维的失误,等,都有可能导致数据误删除,或者是误操作,此时我们就必须快速的恢复数据,避免对正常业务造成过大的影响,甚至出现事故,本文我们按照如下的几种情况来进行分析 ...

最新文章

  1. Liunx中环境变量的配置profile,environment,barshrc
  2. android sqlite触发器,SQLite---使用触发器(Trigger)
  3. 分享一些笔记本电脑日常保养技巧
  4. Spring Boot 解决跨域Cors问题
  5. 过滤JSON中的特殊字符
  6. 宏块与宏块对(附图)
  7. HTML示例03---标题的对齐方式
  8. HeadFirstJava——14_数据结构
  9. mentohust找不到服务器,mentohust最新版
  10. 芯动科技面试——数字IC/FPGA面试案例总结1
  11. java项目大鱼吃小鱼
  12. 火狐浏览器截图整个网页截图 截取整个网页
  13. 故宫元宵节首开夜场,票务系统HTTPS加密护航 1
  14. CSS绘制渐变黑白背景栏
  15. uni-app 介绍,什么是uni-app,它是干嘛的
  16. Mybatis——类型处理器TypeHandler
  17. 一文读懂什么是cookie和session。
  18. zabbix使用web界面监控本机
  19. 换脸方法大汇总:生成对抗网络GAN、扩散模型等
  20. C#必看:《第17章节QQ管理系统》

热门文章

  1. 计算机的物理地址怎么写,电脑物理地址怎么查
  2. Go --- html/template模板包的使用
  3. 【Fortran】STOP语句
  4. 安装华为运动健康beta版本安装失败
  5. virtualbox 菜单栏不见了---如何调出来
  6. 论证可行性有哪几个方面
  7. thinkpad x200 bios 超级密码破解方法
  8. 幸运彩票 分数 15作者 陈越单位 浙江大学
  9. PostgreSQL eighth class
  10. 网络通信学习(四)——通过接入网进入互联网内部,探索接入网和网络运营商