MySQL - Multiple set on LOAD DATA INFILE

前端 未结 5 540
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 03:30

I\'ve a table_name like this:

No | Name | Inserted_Date | Inserted_By
=====================================

and then I\'ve

5条回答
  •  长情又很酷
    2021-01-01 04:17

    Insert bulk more than 7000000 record in 1 minutes in database(superfast query with calculation)

    mysqli_query($cons, '
        LOAD DATA LOCAL INFILE "'.$file.'"
        INTO TABLE tablename
        FIELDS TERMINATED by \',\'
        LINES TERMINATED BY \'\n\'
        IGNORE 1 LINES
        (isbn10,isbn13,price,discount,free_stock,report,report_date)
         SET RRP = IF(discount = 0.00,price-price * 45/100,IF(discount = 0.01,price,IF(discount != 0.00,price-price * discount/100,@RRP))),
             RRP_nl = RRP * 1.44 + 8,
             RRP_bl = RRP * 1.44 + 8,
             ID = NULL
        ')or die(mysqli_error());
    $affected = (int) (mysqli_affected_rows($cons))-1; 
    $log->lwrite('Inventory.CSV to database:'. $affected.' record inserted successfully.');
    

    RRP and RRP_nl and RRP_bl is not in csv but we are calculated that and after insert that.

提交回复
热议问题