It is common to import CSV files into MySQL database. You can do this with phpMyAdmin with small CSV files but with large ones, you would probably encounter the memory error and had to switch to MySQL command line â€œLOAD DATA LOCAL INFILEâ€ to do the job.
It looks like something like this:
LOAD DATA LOCAL INFILE 'your.csv' INTO TABLE `your_table` FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (field1, field2, field3)
And then you encounter another problem that it only imports the first 1 or 2 rows and then it stops. After some researching and trying, I was sure itâ€™s something to do with the â€œLINES TERMINATED BYâ€ directive. Depending on the platform that the CSV file is created on, the line delimiter may be
And you need to be correct on the line delimiter to properly parse the CSV file.
So the solution is to try them all one by one and see which one of them works. Chances are, one of them would make the whole command successfully import ALL rows.
Another simple approach is to deprive the whole command of the â€œLINES TERMINATED BYâ€ directive and let MySQL do the call. Itâ€™ll probably detect things right but in my case, this doesnâ€™t work but specifying â€˜\râ€™.