Importing CSV into MySQL table on Windows
After completing development of one of my apps, I had to load one of my MySQL tables with data. After putting the data in CSV format, I wanted to upload it to my MySQL table. I searched the web and found the syntax to use (I use MySQL workbench and from there I went into the database and created and executed a new query). However, it took awhile for me to figure out how to make the file name work.
Here’s the syntax I used in MySQL Workbench for the query to execute (replace the text in colors with your data):
load data local infile ‘C://yourdirectory/yourdirectory2/filename.csv‘ into table your_table_name fields terminated by ‘,’
enclosed by ‘”‘
lines terminated by ‘\n’
(field1, field2, field3, field4, field5)
(for some reason the characters don’t copy correctly from this post, so you can copy similar syntax from here)