Search code examples
phpmysqltextinsertlarge-data

insert large data from txt to mysql


A simple question: Any ideas on how to import nearly 5M email addresses from a text file to a mysql DB using php quickly? My script is working well, but it is running for 90 hrs now and it inserted only 700.000 entries. Sadly I did not realize until now that I have 5M lines in my txt file. Any suggestion? Thanks in advance.


Solution

  • I don't understand why you don't just use the "load data infile" function that mysql provides if the file is already on your server.

    LOAD DATA INFILE

    The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed.

    As for uniqueness, why don't you just add the UNIQUE constraint to your mysql table? That way you don't need to check for unique constraints?

    I haven't tried this myself but I would try do it like that.