I am building a monitoring application for a machine, position must be read and stored every second for a period of a month. I wrote a procedure to fill a table with initial 0 value.
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`(start_date datetime, end_date datetime)
BEGIN
DECLARE interval_var INT DEFAULT 1;
WHILE end_date >= start_date DO
INSERT INTO table1(datetime, value) VALUES(start_date, 0);
SET start_date = DATE_ADD(start_date, INTERVAL interval_var SECOND);
END WHILE;
END
This process is very slow, and most of the time the connection with the sql database is lost. For example, when I try to fill the table from "2016-01-14 07:00:00" to "2016-01-15 07:00:00" the procedure reached 2016-01-14 07:16:39 and crashed due to lost connection with database.
Is there a more efficient way to create a template table for a month with second increments and 0 values? My monitoring application is built on vb.net and I have tried to create a code on vb to create this template table, but it was slower and more likely to crash than direct procedure on mysql workstation.