mysql load data on duplicate_带有ON DUPLICATE KEY UPDATE的MySQL LOAD DATA INFILE
本站寻求有缘人接手,详细了解请联系站长QQ1493399855
慕勒3428872
这些步骤可用于模拟此功能:1)创建一个新的临时表。CREATE TEMPORARY TABLE temporary_table LIKE target_table;2)(可选)从临时表中删除所有索引以加快速度。SHOW INDEX FROM temporary_table;DROP INDEX `PRIMARY` ON temporary_table;DROP INDEX `some_other_index` ON temporary_table;3)将CSV加载到临时表中LOAD DATA INFILE 'your_file.csv'INTO TABLE temporary_table
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'(field1, field2);4)使用ON DUPLICATE KEY UPDATE复制数据SHOW COLUMNS FROM target_table;INSERT INTO target_tableSELECT * FROM temporary_tableON DUPLICATE KEY UPDATE field1 = VALUES(field1), field2 = VALUES(field2);5)删除临时表DROP TEMPORARY TABLE temporary_table;使用SHOW INDEX FROM和SHOW COLUMNS FROM此过程可以针对任何给定的表自动执行。