Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a insert query multiple times into a table with mySql

For testing the TTFB for single pages loaded by a CMS I wan't to add new pages into my database without doing it one for one inside a CMS. For example I wan't to execute the query as below a 100 times inside a table, but how can I do this in mySql/phpmyadmin?

This query must be execute for 100 times

INSERT INTO `bolt_pages` (`id`, `slug`, `datecreated`, `datechanged`, `datepublish`, `datedepublish`, `username`, `ownerid`, `status`, `templatefields`, `title`, `image`, `teaser`, `body`, `template`) VALUES (NULL, 'hello-world', '2017-05-15 12:01:35', '2017-05-15 13:22:43', '2017-05-15 12:01:13', NULL, '', '1', 'published', '[]', 'Hello world', NULL, '<p>teaser</p>\r\n', '<p>Hello world</p>\r\n', '');
like image 695
CodeWhisperer Avatar asked Mar 09 '23 02:03

CodeWhisperer


1 Answers

With a procedure should be...

DELIMITER $$
CREATE PROCEDURE simple_loop ( )
BEGIN
  DECLARE counter BIGINT DEFAULT 0;

  my_loop: LOOP
    SET counter=counter+1;

    IF counter=100 THEN
      LEAVE my_loop;
    END IF;

    #SELECT counter; #uncomment if you'd like to print the counter

    INSERT INTO `bolt_pages` (`id`, `slug`, `datecreated`, `datechanged`, `datepublish`, `datedepublish`, `username`, `ownerid`, `status`, `templatefields`, `title`, `image`, `teaser`, `body`, `template`) VALUES (NULL, 'hello-world', '2017-05-15 12:01:35', '2017-05-15 13:22:43', '2017-05-15 12:01:13', NULL, '', '1', 'published', '[]', 'Hello world', NULL, '<p>teaser</p>\r\n', '<p>Hello world</p>\r\n', '');

  END LOOP my_loop;
END$$
DELIMITER 
like image 127
javier_domenech Avatar answered Mar 12 '23 04:03

javier_domenech