MySQL数据生成工具mysql_random_data_load
在看MySQL文章的时候偶然发现生成数据的工具,此处直接将软件作者的文档贴了过来,说明了使用方式及下载地址
Random data generator for MySQL
Many times in my job I need to generate random data for a specific table in order to reproduce an issue.
After writing many random generators for every table, I decided to write a random data generator, able to get the table structure and generate random data for it.
Plase take into consideration that this is the first version and it doesn’t support all field types yet!
NOTICE
This is an early stage project.
Supported fields:
| Field type | Generated values |
|---|---|
| tinyint | 0 ~ 0xFF |
| smallint | 0 ~ 0XFFFF |
| mediumint | 0 ~ 0xFFFFFF |
| int - integer | 0 ~ 0xFFFFFFFF |
| bigint | 0 ~ 0xFFFFFFFFFFFFFFFF |
| float | 0 ~ 1e8 |
| decimal(m,n) | 0 ~ 10^(m-n) |
| double | 0 ~ 1000 |
| char(n) | up to n random chars |
| varchar(n) | up to n random chars |
| date | NOW() - 1 year ~ NOW() |
| datetime | NOW() - 1 year ~ NOW() |
| timestamp | NOW() - 1 year ~ NOW() |
| time | 00:00:00 ~ 23:59:59 |
| year | Current year - 1 ~ current year |
| tinyblob | up to 100 chars random paragraph |
| tinytext | up to 100 chars random paragraph |
| blob | up to 100 chars random paragraph |
| text | up to 100 chars random paragraph |
| mediumblob | up to 100 chars random paragraph |
| mediumtext | up to 100 chars random paragraph |
| longblob | up to 100 chars random paragraph |
| longtext | up to 100 chars random paragraph |
| varbinary | up to 100 chars random paragraph |
| enum | A random item from the valid items list |
| set | A random item from the valid items list |
How strings are generated
- If field size < 10 the program generates a random “first name”
- If the field size > 10 and < 30 the program generates a random “full name”
- If the field size > 30 the program generates a “lorem ipsum” paragraph having up to 100 chars.
The program can detect if a field accepts NULLs and if it does, it will generate NULLs ramdomly (~ 10 % of the values).
Usage
mysql_random_data_load <database> <table> <number of rows> [options...]
Options
| Option | Description |
|---|---|
| –bulk-size | Number of rows per INSERT statement (Default: 1000) |
| –debug | Show some debug information |
| –fk-samples-factor | Percentage used to get random samples for foreign keys fields. Default 0.3 |
| –host | Host name/ip |
| –max-fk-samples | Maximum number of samples for fields having foreign keys constarints. Default: 100 |
| –max-retries | Maximum number of rows to retry in case of errors. See duplicated keys. Deafult: 100 |
| –no-progressbar | Skip showing the progress bar. Default: false |
| –password | Password |
| –port | Port number |
| Print queries to the standard output instead of inserting them into the db | |
| –user | Username |
| –version | Show version and exit |
Foreign keys support
If a field has Foreign Keys constraints, random-data-load will get up to --max-fk-samples random samples from the referenced tables in order to insert valid values for the field.
The number of samples to get follows this rules:
1. Get the aproximate number of rows in the referenced table using the rows field in:
EXPLAIN SELECT COUNT(*) FROM <referenced schema>.<referenced table>
1.1 If the number of rows is less than max-fk-samples, all rows are retrieved from the referenced table using this query:
SELECT <referenced field> FROM <referenced schema>.<referenced table>
1.2 If the number of rows is greater than max-fk-samples, samples are retrieved from the referenced table using this query:
SELECT <referenced field> FROM <referenced schema>.<referenced table> WHERE RAND() <= <fk-samples-factor> LIMIT <max-fk-samples>
Example
CREATE DATABASE IF NOT EXISTS test;CREATE TABLE `test`.`t3` (`id` int(11) NOT NULL AUTO_INCREMENT,`tcol01` tinyint(4) DEFAULT NULL,`tcol02` smallint(6) DEFAULT NULL,`tcol03` mediumint(9) DEFAULT NULL,`tcol04` int(11) DEFAULT NULL,`tcol05` bigint(20) DEFAULT NULL,`tcol06` float DEFAULT NULL,`tcol07` double DEFAULT NULL,`tcol08` decimal(10,2) DEFAULT NULL,`tcol09` date DEFAULT NULL,`tcol10` datetime DEFAULT NULL,`tcol11` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,`tcol12` time DEFAULT NULL,`tcol13` year(4) DEFAULT NULL,`tcol14` varchar(100) DEFAULT NULL,`tcol15` char(2) DEFAULT NULL,`tcol16` blob,`tcol17` text,`tcol18` mediumtext,`tcol19` mediumblob,`tcol20` longblob,`tcol21` longtext,`tcol22` mediumtext,`tcol23` varchar(3) DEFAULT NULL,`tcol24` varbinary(10) DEFAULT NULL,`tcol25` enum('a','b','c') DEFAULT NULL,`tcol26` set('red','green','blue') DEFAULT NULL,`tcol27` float(5,3) DEFAULT NULL,`tcol28` double(4,2) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB;
To generate 100K random rows, just run:
mysql_random_data_load test t3 100000 --user=root --password=root
mysql> select * from t3 limit 1\G
*************************** 1. row ***************************id: 1
tcol01: 10
tcol02: 173
tcol03: 1700
tcol04: 13498
tcol05: 33239373
tcol06: 44846.4
tcol07: 5300.23
tcol08: 11360967.75
tcol09: 2017-09-04
tcol10: 2016-11-02 23:11:25
tcol11: 2017-03-03 08:11:40
tcol12: 03:19:39
tcol13: 2017
tcol14: repellat maxime nostrum provident maiores ut quo voluptas.
tcol15: Th
tcol16: Walter
tcol17: quo repellat accusamus quidem odi
tcol18: esse laboriosam nobis libero aut dolores e
tcol19: Carlos Willia
tcol20: et nostrum iusto ipsa sunt recusa
tcol21: a accusantium laboriosam voluptas facilis.
tcol22: laudantium quo unde molestiae consequatur magnam.
tcol23: Pet
tcol24: Richard
tcol25: c
tcol26: green
tcol27: 47.430
tcol28: 6.12
1 row in set (0.00 sec)
效果良好

How to download the precompiled binaries
There are binaries available for each version for Linux and Darwin. You can find compiled binaries for each version in the releases tab:
https://github.com/Percona-Lab/mysql_random_data_load/releases
相关文章:
MySQL数据生成工具mysql_random_data_load
在看MySQL文章的时候偶然发现生成数据的工具,此处直接将软件作者的文档贴了过来,说明了使用方式及下载地址 Random data generator for MySQL Many times in my job I need to generate random data for a specific table in order to reproduce an is…...
iPhone 15分辨率,屏幕尺寸,PPI 详细数据对比 iPhone 15 Plus、iPhone 15 Pro、iPhone 15 Pro Max
史上最全iPhone 机型分辨率,屏幕尺寸,PPI详细数据!已更新到iPhone 15系列! 点击放大查看高清图 !...
Java实验一 Java语言基础(12题)
文章目录: 1、我国历法中的天干、地支和生肖的排列是有规律的。天干的顺序是“甲乙丙丁戊己庚辛壬癸”,地支的顺序是“子丑寅卯辰巳午未申酉戌亥”,生肖的顺序是“鼠牛虎兔龙蛇马羊猴鸡狗猪”。天干、地支、生肖的计算方法非常简单ÿ…...
Unity可视化Shader工具ASE介绍——5、ASE快捷键和常用节点介绍
大家好,我是阿赵。 继续介绍Unity可视化Shader插件ASE。这次来说一些常用节点的快捷键,顺便介绍一些常用的节点。 用过UE引擎的朋友可能会发现,ASE的整体用法和UE的材质节点编辑器非常的像,甚至连很多节点的快捷键都和UE的…...
【axmol-2.1 vs cocos2dx性能备忘】
axmol-2.1-08c0605 cocos2d-x-4.0 cocos2d-x-3.17.1 结论 从多边形Sprite渲染性能测试用例看,axmol相对于cocos2d-x-4.0提升42%, 相对于cocos2d-x-3.17.1提升30.8%...
idea compile项目正常,启动项目的时候build失败,报“找不到符号”等问题
1、首先往上找,看能不能找到如下报错信息 You aren’t using a compiler supported by lombok, so lombok will not work and has been disabled. 2、这种问题属于lombok编译失败导致,可能原因是依赖jar包没有更新到最新版本 3、解决方案 1)…...
从零开始:深入理解Kubernetes架构及安装过程
K8s环境搭建 文章目录 K8s环境搭建集群类型安装方式环境规划克隆三台虚拟机系统环境配置集群搭建初始化集群(仅在master节点)配置环境变量(仅在master节点)工作节点加入集群(knode1节点及knode2节点)安装ca…...
混淆技术研究笔记(五)混淆后如何反篡改?
有了上一节的基础工具后,接下来要考虑如何反篡改。 本文采用的是对混淆后的代码,针对某些关键包的字节码数据计算md5值,对所有类计算完成后对md5值进行排序,排序后拼接字符串再次计算md5值,最后通过私钥对md5进行RSA对…...
QTableWidget 表格部件
QTableWidget是QT中的表格组件类。一般用来展示多行多列的数据,是QT中使用较多的控件之一。1、QTableWidgetItem对象 QTableWidget中的每一个单元格都是一个QTableWidgetItem对象,因此先介绍下QTableWidgetItem的常用方法。 1.1、设置文本内容 void QT…...
MySQL join的底层原理
文章目录 前言一、join是什么?二、join的使用例子三、join的连接方式1、简单嵌套2、索引嵌套3、块嵌套4、哈希连接 前言 面试的时候,被问到join 的底层原理,之前没有深入了解过,今天对这个知识点进行一个学习。 一、join是什么&…...
如何在 Spring Boot 中实现容错机制
在 Spring Boot 中实现容错机制 容错机制是构建健壮和可靠的应用程序的重要组成部分。它可以帮助应用程序在面对异常或故障时保持稳定运行。Spring Boot提供了多种机制来实现容错,包括异常处理、断路器、重试和降级等。本文将介绍如何在Spring Boot中实现这些容错机…...
Sqlite3 查询 今日、昨日、本周、上周、本月、上月、本季度、上季度、本年
一、使用Between AND select * from 表名 where 字段名 Between ‘2019-1-01 00:00:00’ AND ‘2019-7-12 23:59:59’ 二、使用>,< select * from 表名 where 字段名 > ‘2019-1-01 00:00:00’ and 字段名 < ‘2019-12-12 23:59:59’ 三、升降序 select * from 表…...
IDEA XML文件里写SQL比较大小条件
背景 最近开发的时候,有一个需求的查询需要支持范围查询[a,b),并且查询的结果要求查询的范围含头端点不含尾端点。因为between…and…查询的范围是含头含尾的,因而不能使用。 因此打算直接使用>和<来比较实现,使用>的时…...
Camtasia Studio2024最新版本正式更新上线!
Camtasia Studio2024是一款专门录制屏幕动作的工具,它能在任何颜色模式下轻松地记录 屏幕动作,包括影像、音效、鼠标移动轨迹、解说声音等等,简单实用的视频录制软件,游戏的精彩画面,网络视频,屏幕录制可以让您录制屏幕所有内容视频录制支持3…...
各种业务场景调用API代理的API接口教程
API代理的API接口在各种业务场景中具有广泛的应用,本文将介绍哪些业务场景可以使用API代理的API接口,并提供详细的调用教程和代码演示,同时,我们还将讨论在不同场景下使用API代理的API接口所带来的好处。 哪些业务场景可以使用API…...
安卓App使用HttpURLConnection发送请求与上传文件
安卓原生App开发时常用的http开发工具 系统内置http请求工具为 HttpURLConnectionhttpClient 是 apache 的开源工具okHttp 使用更简单,语法相对HttpURLConnection也简洁了许多,需要在graddle添加依赖。 本文主要讲解如何使用HttpURConnection向服务器发…...
【Linux服务端搭建及使用】
连接服务器的软件:mobaxterm 设置root 账号 sudo apt-get install passwd #安装passwd 设置方法 sudo passwd #设置root密码 su root #切换到root账户设置共享文件夹 一、强制删除原有环境 1.删除python rpm -qa|grep pytho…...
前端JavaScript入门到精通,javascript核心进阶ES6语法、API、js高级等基础知识和实战 —— JS进阶(三)
思维导图 1.编程思想 1.1 面向过程编程 1.2 面向对象编程 (oop) 2. 构造函数 3. 原型 3.1 原型 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta http-equiv"X-UA-Compatible" content"IE…...
Linux 指令心法(十一)`tail` 显示文本文件的末尾部分
文章目录 命令的概述和用途命令的用法命令行选项和参数的详细说明命令的示例命令的注意事项或提示 命令的概述和用途 tail 是一个用于显示文本文件的末尾部分的命令。它在 Linux 和 Unix 系统中非常有用,因为它允许用户查看文件的最后几行,以便实时监视…...
Mac mov转mp4,详细转换步骤
Mac mov转mp4怎么转?视频文件格式为.mov是由Apple公司所开发的特殊格式。因其只能在苹果设备上播放,与他人分享时就会变得困难。为此,我们通常会选择使用MP4这种最受欢迎的视频格式。在日常使用中,MP4成为了大家首选的视频格式。而…...
python/java环境配置
环境变量放一起 python: 1.首先下载Python Python下载地址:Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个,然后自定义,全选 可以把前4个选上 3.环境配置 1)搜高级系统设置 2…...
376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...
如何在看板中有效管理突发紧急任务
在看板中有效管理突发紧急任务需要:设立专门的紧急任务通道、重新调整任务优先级、保持适度的WIP(Work-in-Progress)弹性、优化任务处理流程、提高团队应对突发情况的敏捷性。其中,设立专门的紧急任务通道尤为重要,这能…...
Mac软件卸载指南,简单易懂!
刚和Adobe分手,它却总在Library里给你写"回忆录"?卸载的Final Cut Pro像电子幽灵般阴魂不散?总是会有残留文件,别慌!这份Mac软件卸载指南,将用最硬核的方式教你"数字分手术"࿰…...
工业自动化时代的精准装配革新:迁移科技3D视觉系统如何重塑机器人定位装配
AI3D视觉的工业赋能者 迁移科技成立于2017年,作为行业领先的3D工业相机及视觉系统供应商,累计完成数亿元融资。其核心技术覆盖硬件设计、算法优化及软件集成,通过稳定、易用、高回报的AI3D视觉系统,为汽车、新能源、金属制造等行…...
OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别
OpenPrompt 和直接对提示词的嵌入向量进行训练有什么区别 直接训练提示词嵌入向量的核心区别 您提到的代码: prompt_embedding = initial_embedding.clone().requires_grad_(True) optimizer = torch.optim.Adam([prompt_embedding...
SpringCloudGateway 自定义局部过滤器
场景: 将所有请求转化为同一路径请求(方便穿网配置)在请求头内标识原来路径,然后在将请求分发给不同服务 AllToOneGatewayFilterFactory import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; impor…...
Java面试专项一-准备篇
一、企业简历筛选规则 一般企业的简历筛选流程:首先由HR先筛选一部分简历后,在将简历给到对应的项目负责人后再进行下一步的操作。 HR如何筛选简历 例如:Boss直聘(招聘方平台) 直接按照条件进行筛选 例如:…...
全面解析各类VPN技术:GRE、IPsec、L2TP、SSL与MPLS VPN对比
目录 引言 VPN技术概述 GRE VPN 3.1 GRE封装结构 3.2 GRE的应用场景 GRE over IPsec 4.1 GRE over IPsec封装结构 4.2 为什么使用GRE over IPsec? IPsec VPN 5.1 IPsec传输模式(Transport Mode) 5.2 IPsec隧道模式(Tunne…...
Web 架构之 CDN 加速原理与落地实践
文章目录 一、思维导图二、正文内容(一)CDN 基础概念1. 定义2. 组成部分 (二)CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 (三)CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 …...
