MySQL 快速创造实验数据

前言

我已经有表结构,想造一些实验数据。

除了用存储过程和自己写程序,还有什么快速的方法?本期的主角是 mysql_random_data_load

安装

下载地址:https://github.com/Percona-Lab/mysql_random_data_load

在这里插入图片描述

下载对应系统版本的文件,开箱即用。

#直接上传并解压
tar -zxvf mysql_random_data_load_0.1.12_Linux_x86_64.tar.gz 

#测试
./mysql_random_data_load --help

使用方法

创建一个测试的空表

CREATE TABLE `cs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `tcol01` tinyint DEFAULT NULL,
  `tcol02` smallint DEFAULT NULL,
  `tcol03` mediumint DEFAULT NULL,
  `tcol04` int DEFAULT NULL,
  `tcol05` bigint 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 DEFAULT NULL,
  `tcol14` varchar(100) DEFAULT NULL,
  `tcol15` char(2) DEFAULT NULL,
  `tcol16` blob,
  `tcol17` text,
  `tcol18` mediumtext,
  `tcol19` mediumblob,
  `tcol20` longblob,
  `tcol21` longtext,
  `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;

开始造数

./mysql_random_data_load -h127.0.0.1 -uroot -plmx --max-threads=8 ceshi cs 10000 --debug
#结果
INFO[2025-01-03T15:23:49+08:00] Starting                                     
DEBU[2025-01-03T15:23:49+08:00] Must run 10 bulk inserts having 1000 rows each 
INFO[2025-01-03T15:24:01+08:00] 10000 rows inserted    

填充后效果

mysql> select count(*) from cs;
+----------+
| count(*) |
+----------+
|    10000 |
+----------+
1 row in set (0.06 sec)

mysql> select * from cs order by id desc limit 1\G 
*************************** 1. row ***************************
    id: 10000
tcol01: 6
tcol02: 162
tcol03: 476860
tcol04: 793751056
tcol05: 3513736601266740361
tcol06: 0.054518
tcol07: 0.676275
tcol08: 0.00
tcol09: 2025-01-03
tcol10: 2024-04-08 16:04:54
tcol11: 2024-07-23 15:07:19
tcol12: 22:26:20
tcol13: 2024
tcol14: eius nemo placeat quo voluptas.
tcol15: Te
tcol16: 0x646F6C6F7269627573206D61676E616D2064656269746973206576656E6965742E
tcol17: est odit minima aliquid vitae pariatur.
tcol18: quae sunt delectus non iusto assumenda.
tcol19: 0x717561736920656F7320766572697461746973206163637573616D757320646F6C6F72656D2069707361206163637573616E7469756D2E
tcol20: 0x76656C697420746F74616D206120656C6967656E6469207265696369656E64697320656975732E
tcol21: quia ut voluptas at.
tcol23: Gre
tcol24: 0x4C696E6461
tcol25: b
tcol26: red
tcol27: 0.832
tcol28: 0.68
1 row in set (0.00 sec)

这里提供一个命令模版:

./mysql_random_data_load -h127.0.0.1 -u'用户' -p'密码' --max-threads=线程数 库名 表名 造数多少行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值