Importing CSV file into mysql table

I had a few problems when trying to import a CSV file which had quotes for the fields. It was inserting each quote as part of the value.  I know you can get around that with msyql, but there is a way to search and replace the quotes with nothing with the following linux command:

sed s/\"//g file_name.csv > new_file_name.csv

Once you are done with that, then you can log into your mysql server via shell then run the following command:

LOAD DATA LOCAL INFILE 'new_file_name.csv' INTO TABLE {yourtablename} FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (yourfield1,yourfield2);


That’s it.

LukeImporting CSV file into mysql table

Leave a Reply

Your email address will not be published. Required fields are marked *