How to generate 1000000 rows with random data?

前端 未结 2 1830
说谎
说谎 2021-02-05 18:26

Background

Im working on some kind of data logger.

I want to try how much storage space I need for 1000000 (1M) rows and how Raspberry Pi deals

相关标签:
2条回答
  • 2021-02-05 18:50

    Try it with a stored procedure (replace 1000 with desired amount of rows, and 2014 with test year, also see generate random timestamps in mysql)

    CREATE TABLE `data` 
    (
      `id`         bigint(20) NOT NULL      AUTO_INCREMENT,
      `datetime`   timestamp  NULL          DEFAULT CURRENT_TIMESTAMP,
      `channel`    int(11)                  DEFAULT NULL,
      `value`      float                    DEFAULT NULL,
    
      PRIMARY KEY (`id`)
    );
    
    
    DELIMITER $$
    CREATE PROCEDURE generate_data()
    BEGIN
      DECLARE i INT DEFAULT 0;
      WHILE i < 1000 DO
        INSERT INTO `data` (`datetime`,`value`,`channel`) VALUES (
          FROM_UNIXTIME(UNIX_TIMESTAMP('2014-01-01 01:00:00')+FLOOR(RAND()*31536000)),
          ROUND(RAND()*100,2),
          1
        );
        SET i = i + 1;
      END WHILE;
    END$$
    DELIMITER ;
    
    CALL generate_data();
    

    Modify to your needs. To delete the procedure:

    DROP PROCEDURE generate_data;
    

    Maybe this can give you a start!

    0 讨论(0)
  • 2021-02-05 18:56

    We have MySQL Random Data Generator - easy to use procedure for generating the random data internally from mysql itself.

    0 讨论(0)
提交回复
热议问题