Page 1 of 1
Importing CSV into mysql
Posted: Wed Dec 05, 2007 1:47 pm
by GeXus
I've always had a hard time importing csv's into mysql... Is there a trick or an easy way? Do the column names in the table have to match that in the CSV? what if it uses different naming conversion or has additional columns?
Posted: Wed Dec 05, 2007 1:49 pm
by Christopher
Code: Select all
LOAD DATA INFILE '/path/to/my/file.csv' INTO TABLE mytable;
There are options to specify delimeters, etc. See the manual.
Posted: Wed Dec 05, 2007 2:20 pm
by GeXus
arborint wrote:Code: Select all
LOAD DATA INFILE '/path/to/my/file.csv' INTO TABLE mytable;
There are options to specify delimeters, etc. See the manual.
I mean yeah I can see where you can specify delimiters and stuff, but like how do you map the column names in the csv to column names in a table?
Posted: Wed Dec 05, 2007 2:29 pm
by feyd
They fill in in-order.
Posted: Wed Dec 05, 2007 2:30 pm
by GeXus
feyd wrote:They fill in in-order.
So what if I have a table as such
id | one | two | three | four
and a CSV file like
oneName | twoName | threeName | fourName
I have the id column in there that autoincrements
Posted: Wed Dec 05, 2007 2:33 pm
by feyd
This is something you can try.
Posted: Wed Dec 05, 2007 2:33 pm
by GeXus
feyd wrote:This is something you can try.
Gotcha! (and it doesn't work)
Posted: Wed Dec 05, 2007 4:29 pm
by Christopher
Create a temporary table with the same columns as your CSV data, then INSERT ... SELECT into your target table.
Posted: Fri Dec 07, 2007 3:47 am
by Kieran Huggins
a HEAP table is nice and fast for temp tables.