听说mysql数据量达到5000万的以后,性能就急剧下降,干了这么久开发,还没看见过这么大的数据量,并且还是需要有关联关系的,因为要测试SQL JOIN ,今天就发现有这样一个叫做mysql-tester的工具,可以生成模拟电商的数据库,大数据量,具有关联关系!
而且只需要三步就可以生成数据了!
步骤:
1. 下载jar包
2. 运行数据库建表脚本
3. 运行jar 生成测试数据
下载可执行jar包,下载链接 :
(https://github.com/wuda0112/mysql-tester/releases/)-
建表脚本:
-- MySQL Script generated by MySQL Workbench -- Fri Mar 8 16:04:52 2019 -- Model: New Model Version: 1.0 -- MySQL Workbench Forward Engineering -- ----------------------------------------------------- -- Schema mysql_tester -- -- mysql_tester . 数据自动生成 -- ----------------------------------------------------- CREATE SCHEMA IF NOT EXISTS `mysql_tester` ; USE `mysql_tester` ; -- ----------------------------------------------------- -- Table `mysql_tester`.`individual_user` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mysql_tester`.`individual_user` ( `id` BIGINT UNSIGNED NOT NULL, `username` VARCHAR(45) NOT NULL COMMENT '用户名', `password` VARCHAR(45) NOT NULL COMMENT '密码', `mobile_phone` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '手机', `email` VARCHAR(45) NOT NULL DEFAULT '' COMMENT '邮箱', `status` TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态. \n1 : 正常', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `create_user` BIGINT UNSIGNED NOT NULL, `last_modify_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `last_modify_user` BIGINT UNSIGNED NOT NULL, `is_deleted` BIGINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE INDEX `idx_mobile_phone` (`mobile_phone` ASC), UNIQUE INDEX `idx_email` (`email` ASC), UNIQUE INDEX `idx_username` (`username` ASC)) COMMENT = '个人用户-基本信息'; -- ----------------------------------------------------- -- Table `mysql_tester`.`shop` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mysql_tester`.`shop` ( `id` BIGINT UNSIGNED NOT NULL, `user_id` BIGINT UNSIGNED NOT NULL COMMENT '所属用户ID.', `shop_name` VARCHAR(45) NOT NULL COMMENT '店铺名称', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `create_user` BIGINT UNSIGNED NOT NULL, `last_modify_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `last_modify_user` BIGINT UNSIGNED NOT NULL, `is_deleted` BIGINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`), INDEX `fk_user_id_idx` (`user_id` ASC)) COMMENT = '店铺信息'; -- ----------------------------------------------------- -- Table `mysql_tester`.`item` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mysql_tester`.`item` ( `id` BIGINT UNSIGNED NOT NULL, `shop_id` BIGINT UNSIGNED NOT NULL COMMENT '所属店铺ID . fk shop.id', `item_type` TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '商品类型 .\n0 . 简单类型,比如:书\n1 . 多规格类型:比如:衣服\n参考 : https://learnwoo.com/woocommerce-different-product-types/', `item_name` VARCHAR(45) NOT NULL COMMENT '商品名称', `category_one_id` BIGINT UNSIGNED NULL COMMENT '一级分类 . fk item_category.id', `category_two_id` BIGINT UNSIGNED NULL COMMENT '二级分类 . fk item_category.id', `category_three_id` BIGINT UNSIGNED NULL COMMENT '三级分类 . fk item_category.id', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `create_user` BIGINT UNSIGNED NOT NULL, `last_modify_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `last_modify_user` BIGINT UNSIGNED NOT NULL, `is_deleted` BIGINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`), INDEX `fk_shop_id_idx` (`shop_id` ASC), INDEX `fk_category_one_id_idx` (`category_one_id` ASC), INDEX `fk_category_two_id_idx` (`category_two_id` ASC), INDEX `fk_category_three_id_idx` (`category_three_id` ASC)) COMMENT = '商品'; -- ----------------------------------------------------- -- Table `mysql_tester`.`warehouse` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mysql_tester`.`warehouse` ( `id` BIGINT UNSIGNED NOT NULL, `user_id` BIGINT UNSIGNED NOT NULL COMMENT '所属用户ID', `shop_id` BIGINT UNSIGNED NOT NULL COMMENT '所属店铺ID', `warehouse_type` TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '综合仓类型 . \n\n1. virtual . 没有实际仓库\n2. solid . 实体仓库 . 没错 , 就是这个单词 , 从美剧中学的 . ', `warehouse_name` VARCHAR(45) NOT NULL COMMENT '仓库名称', `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `create_user` BIGINT UNSIGNED NOT NULL, `last_modify_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `last_modify_user` BIGINT UNSIGNED NOT NULL, `is_deleted` BIGINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`id`), INDEX `fk_individual_user_id_idx` (`user_id` ASC), INDEX `fk_shop_id_idx` (`shop_id` ASC)) COMMENT = '仓库. 代表存放商品的仓库.';
-
执行jar
输入命令,启动.默认连接到本地mysql,即: localhost:3306 java -jar mysql-tester-${VERSION}.jar --mysql-username=用户名 --mysql-password=密码 支持的选项 --max-item-per-user <arg> 每个用户最多有多少商品数;在生成数据时,随机为每个用户生成商品,数量取值范围是 [0,MAX](default=10).比如默认生成10000个用户,每个用户 最多10个商品,那么大致就可以知道生成的数据规模 --mysql-max-connection <arg> mysql最大连接数(default=25) --mysql-password <arg> mysql password --mysql-url <arg> mysql连接url(default=jdbc:mysql://localho st:3306/?serverTimezone=UTC) --mysql-username <arg> mysql username --thread <thread> 生成数据的线程数(default=50) --user-count <arg> 用户表生成多少行记录,同时也是店铺表和仓库表的记录数,因为一个用户只拥有一个店 铺和一个仓库(default=10000),当生成的记录数达到该值时,数据生成 任务结束、