• MySQL快速创造百万测试数据


    CREATE TABLE `vote_record_memory` (
    `id` INT (11) NOT NULL AUTO_INCREMENT,
    `user_id` VARCHAR (20) NOT NULL,
    `vote_id` INT (11) NOT NULL,
    `group_id` INT (11) NOT NULL,
    `create_time` datetime NOT NULL,
    PRIMARY KEY (`id`),
    KEY `index_id` (`user_id`) USING HASH
    ) ENGINE = memory AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 ;


    CREATE TABLE `vote_record` (
    `id` INT (11) NOT NULL AUTO_INCREMENT,
    `user_id` VARCHAR (20) NOT NULL,
    `vote_id` INT (11) NOT NULL,
    `group_id` INT (11) NOT NULL,
    `create_time` datetime NOT NULL,
    PRIMARY KEY (`id`),
    KEY `index_user_id` (`user_id`) USING HASH
    ) ENGINE = INNODB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8 ;

    DELIMITER //
    CREATE FUNCTION `rand_string`(n INT) RETURNS varchar(255) CHARSET latin1
    BEGIN
    DECLARE chars_str varchar(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    DECLARE return_str varchar(255) DEFAULT '' ;
    DECLARE i INT DEFAULT 0;
    WHILE i < n DO
    SET return_str = concat(return_str,substring(chars_str , FLOOR(1 + RAND()*62 ),1));
    SET i = i +1;
    END WHILE;
    RETURN return_str;
    END //

    DELIMITER //
    CREATE PROCEDURE `add_vote_memory`(IN n int)
    BEGIN
    DECLARE i INT DEFAULT 1;
    WHILE (i <= n ) DO
    INSERT into vote_record_memory (user_id,vote_id,group_id,create_time ) VALUEs (rand_string(20),FLOOR(RAND() * 1000),FLOOR(RAND() * 100) ,now() );
    set i=i+1;
    END WHILE;
    END //

    CALL add_vote_memory(1000000) //

    delimiter end ;

    delimiter ;


    INSERT into vote_record SELECT * from vote_record_memory;

  • 相关阅读:
    MySQL(一)序
    Mockito 小结
    如何入门一个开源软件
    面经
    琐碎的想法(四)键盘布局、快捷键的由来
    琐碎的想法(二)网络协议——人们给计算机的一组“约定”
    Java源码赏析(六)Class<T> 类
    Java随谈(五)Java常见的语法糖
    Java随谈(四)JDK对并发的支持
    Event Loop和宏任务微任务
  • 原文地址:https://www.cnblogs.com/hankyoon/p/7444650.html
Copyright © 2020-2023  润新知