Import large csv file to mysql database using php

后端 未结 2 369
陌清茗
陌清茗 2020-12-30 12:21

I have a very large CSV file (150 MB). What is the best way to import it to MySQL? I have to do some manipulation in PHP before inserting it into the MySQL table.

2条回答
  •  难免孤独
    2020-12-30 12:56

    You could take a look at LOAD DATA INFILE in MySQL.

    You might be able to do the manipulations once the data is loaded into MySQL, rather than first reading it into PHP. First store the raw data in a temporary table using LOAD DATA INFILE, then transform the data to the target table using a statement like the following:

    INSERT INTO targettable (x, y, z)
    SELECT foo(x), bar(y), z
    FROM temptable
    

提交回复
热议问题