I have a csv file, maybe 1000 or more rows, and echo row’s data is related to two table in mysql. Example,
table `book`(id, title, …) table `scene`(id, book_id, short_content, position…)
And the csv file look like:
I want to extract data from it and save it to mysql. Also in the mysql maybe already have the same record, so I don’t want save the same data to mysql. My solution is:
- First, fetch all the data related to the file, a big data set labeled
- Second, for each row in file compare to the
BSand create the book, and store the book_id for his
- Finally, batch create the
This is my poor solution, and if the csv file has 1000 rows, then the solution will take a large memory space and 1000 + 1 times mysql calls.
Can anyone give me a better solution. Thanks.