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成为了大家首选的视频格式。而…...
在rocky linux 9.5上在线安装 docker
前面是指南,后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...
多模态商品数据接口:融合图像、语音与文字的下一代商品详情体验
一、多模态商品数据接口的技术架构 (一)多模态数据融合引擎 跨模态语义对齐 通过Transformer架构实现图像、语音、文字的语义关联。例如,当用户上传一张“蓝色连衣裙”的图片时,接口可自动提取图像中的颜色(RGB值&…...

linux arm系统烧录
1、打开瑞芯微程序 2、按住linux arm 的 recover按键 插入电源 3、当瑞芯微检测到有设备 4、松开recover按键 5、选择升级固件 6、点击固件选择本地刷机的linux arm 镜像 7、点击升级 (忘了有没有这步了 估计有) 刷机程序 和 镜像 就不提供了。要刷的时…...

Module Federation 和 Native Federation 的比较
前言 Module Federation 是 Webpack 5 引入的微前端架构方案,允许不同独立构建的应用在运行时动态共享模块。 Native Federation 是 Angular 官方基于 Module Federation 理念实现的专为 Angular 优化的微前端方案。 概念解析 Module Federation (模块联邦) Modul…...
相机Camera日志分析之三十一:高通Camx HAL十种流程基础分析关键字汇总(后续持续更新中)
【关注我,后续持续新增专题博文,谢谢!!!】 上一篇我们讲了:有对最普通的场景进行各个日志注释讲解,但相机场景太多,日志差异也巨大。后面将展示各种场景下的日志。 通过notepad++打开场景下的日志,通过下列分类关键字搜索,即可清晰的分析不同场景的相机运行流程差异…...

微信小程序云开发平台MySQL的连接方式
注:微信小程序云开发平台指的是腾讯云开发 先给结论:微信小程序云开发平台的MySQL,无法通过获取数据库连接信息的方式进行连接,连接只能通过云开发的SDK连接,具体要参考官方文档: 为什么? 因为…...

python执行测试用例,allure报乱码且未成功生成报告
allure执行测试用例时显示乱码:‘allure’ �����ڲ����ⲿ���Ҳ���ǿ�&am…...
Python 训练营打卡 Day 47
注意力热力图可视化 在day 46代码的基础上,对比不同卷积层热力图可视化的结果 import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms from torch.utils.data import DataLoader import matplotlib.pypl…...
用 Rust 重写 Linux 内核模块实战:迈向安全内核的新篇章
用 Rust 重写 Linux 内核模块实战:迈向安全内核的新篇章 摘要: 操作系统内核的安全性、稳定性至关重要。传统 Linux 内核模块开发长期依赖于 C 语言,受限于 C 语言本身的内存安全和并发安全问题,开发复杂模块极易引入难以…...

深入解析光敏传感技术:嵌入式仿真平台如何重塑电子工程教学
一、光敏传感技术的物理本质与系统级实现挑战 光敏电阻作为经典的光电传感器件,其工作原理根植于半导体材料的光电导效应。当入射光子能量超过材料带隙宽度时,价带电子受激发跃迁至导带,形成电子-空穴对,导致材料电导率显著提升。…...