Skip to content

Instantly share code, notes, and snippets.

@theothermattm
Created August 20, 2019 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theothermattm/91e850598cb432fa210fff2bc0d8e3dd to your computer and use it in GitHub Desktop.
Save theothermattm/91e850598cb432fa210fff2bc0d8e3dd to your computer and use it in GitHub Desktop.
Create Dummy Data with MySQL Stored Proc
/* based on https://stackoverflow.com/a/17268740/288935 */
CREATE PROCEDURE insert_test_data()
BEGIN
DECLARE i INT default 1;
DECLARE mydate DATE DEFAULT NOW();
SET mydate = DATE_ADD('2017-05-01 00:01:00', INTERVAL FLOOR(RAND() * 700) DAY);
WHILE i < 1000000 DO
INSERT INTO `telemetry_test` (`humidity`, `temperature`, `sql_insert`, `sql_update`)
select
FLOOR(RAND() * 40), FLOOR(RAND() * 80), mydate, mydate;
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;
CALL insert_test_data();
DROP PROCEDURE insert_test_data;
@theothermattm
Copy link
Author

Takes a while to run..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment