如何使用mySql多次执行插入查询到表中

时间:2017-05-15 12:05:03

标签: mysql sql phpmyadmin

为了测试由CMS加载的单个页面的TTFB,我不想将新页面添加到我的数据库中,而不是在CMS内一对一地进行。例如,我不想在表格中执行100次以下的查询,但是如何在mySql / phpmyadmin中执行此操作?

此查询必须执行100次

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', '');

2 个答案:

答案 0 :(得分:4)

程序应该是......

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 

答案 1 :(得分:1)

您可以使用Repeat,也可以创建procedure

SET @K = 0;
    lab1: REPEAT
    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', '');
    Set @k = @k +1;
    UNTIL @K > 100 END REPEAT lab1;