Import CSV to Update rows in table

后端 未结 3 895
既然无缘
既然无缘 2020-12-05 07:40

There are approximately 26K products (posts) and each product has meta values like this:

\"enter

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 08:12

    You can use temporary table to hold the update data and then run single update statement.

    CREATE TEMPORARY TABLE temp_update_table (meta_key, meta_value)
    
    LOAD DATA INFILE 'your_csv_pathname' 
    INTO TABLE temp_update_table FIELDS TERMINATED BY ';' (meta_key, meta_value); 
    
    UPDATE "table"
    INNER JOIN temp_update_table on temp_update_table.meta_key = "table".meta_key
    SET "table".meta_value = temp_update_table.meta_value;
    
    DROP TEMPORARY TABLE temp_update_table;
    

提交回复
热议问题