我想一次性插入至少500,000条新记录。我在其中使用了while循环程序。我的查询工作正常,但执行时间很长。所以,我正在寻找一种解决方案,使用它可以更快地插入大量数据。我已经通过了许多链接,但我没有发现它们足智多谋。
注意:
以下是我的程序:
BEGIN
DECLARE x INT;
DECLARE start_s INT;
DECLARE end_s INT;
SET x = 0;
PREPARE stmt FROM
'insert into primary_packing(job_id, barcode, start_sn, end_sn, bundle_number, client_code, deno, number_sheets, number_pins, status)
values (?,?,?,?,?,?,?,?,?,?)';
SET @job_id = job_id, @barcode = barcode, @bundle_number = bundle_number, @client_code = client_code, @deno = deno, @number_sheets = number_sheets, @number_pins = number_pins, @status = 1;
set @start_sn = start_sn;
set @end_sn = end_sn;
WHILE x <= multiply DO
set @start_s = (start_sn+(diff*x));
set @end_s = ((end_sn-1)+(diff*x)+diff);
EXECUTE stmt USING @job_id, @barcode, @start_s, @end_s, @bundle_number, @client_code, @deno, @number_sheets, @number_pins ,@status;
SET x = x + 1;
END WHILE;
DEALLOCATE PREPARE stmt;
END
答案 0 :(得分:2)
使用MYSQL命令 LOAD DATA INFILE 将 .csv 文件记录加载到特定表格。
有关更多信息,例如。请提供以下链接