Uploading CSV with headers to MySQL

I want to upload a CSV file into an existing table in a MySQL DB.
I gather that the way this is done is with LOAD DATA INFILE.
If my understanding it correct, the file itself must be data only - no headers, OR you must instruct MySQL to ignore the first line.

What I would like to know is, is there a way to import the data WITH headers and have MySQL use the headers to channel the data into the right buckets?  If possible I don't want to use headerless data because it introduces a risk of compromised data integrity if a file with fields in the wrong order is uploaded.
shachoAsked:
Who is Participating?
 
jimyXCommented:
> is there a way to import the data WITH headers and have MySQL use the headers to channel the data into the right buckets?

That would have been possible if MySQL supports "Prepared Stmt" over Load Data. At the moment it does not.

The way I see it, you are going to need assisting mechanism to translate the CSV header for MySQL by preparing the SQL Query.
0
 
shachoAuthor Commented:
I see.  OK - I guess I'll use a 3rd party tool, then.  Thanks!

Mike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.