mysql快速构造测试数据的工具
工具特性
- 随意创建mysql表类型,支持所有数据类型,自动根据表字段类型填充任意数据量数据;
- 支持mysql5.6、mysql5.7、mysql8.0
- 详细的特性,下载工具后看readme.me文档
工具下载地址
github地址:https://github.com/Percona-Lab/mysql_random_data_load/releases
工具使用流程
-
下载工具并进行解压,注意将工具放在安装mysql数据库的服务器上
-
在mysql数据库中创建库和表
-
执行脚本(./mysql_random_data_load test t3 10 --user=root --password=123456)进行构造数据
- 进入数据库,select count(*) from xx,检查数据是否构造成功
工具使用方法
1、将下载的文件上传到linux的某个自己新建的文件夹下
2、执行解压文件
#解压gz gunzip mysql_random_data_load_0.1.12_Linux_x86_64.tar.gz #解压tar tar xvf mysql_random_data_load_0.1.12_Linux_x86_64.tar
3、解压后的显示如下
4、 在mysql数据库中创建一个库和表,验证工具
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;
5、 向数据库中进行构造数据,如下示例,则表示构造成功
#./mysql_random_data_load 库名 表名 数据条数 --user=用户名 --password=密码
./mysql_random_data_load test t3 10 --host=192.168.30.117 --user=root --password=123456 --port=3308
工具常用设置参数
|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|Print queries to the standard output instead of inserting them into the db|
|--user|Username|
|--version|Show version and exit|
工具支持的数据类型
|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|
1.作者:Syw 2.出处:http://www.cnblogs.com/syw20170419/ 3.本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 4.如果文中有什么错误,欢迎指出。以免更多的人被误导。 |