-1

How should I specify the columns names when I want to load a MySQL table from a local .csv file using the LOAD DATA LOCAL FILE command in MySQL?

2
  • I'm voting to reopen this, since the other question stackoverflow.com/questions/4202564/… has no accepted answer and an incorrect answer before the correct one. Close again if you disagree. Commented Dec 6, 2019 at 21:17
  • @ysth having an accepted answer is not a criterion for a dupe target and the most upvoted answer is a correct answer, altgough other answers there also work. Your answer is just a repeat of what's already there, confirming that is indeed a duplicate. Commented Dec 6, 2019 at 22:15

1 Answer 1

0

You specify a comma seperated list of columns, in parentheses, at the end (but before the optional SET parameters).

See https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-column-list

Sign up to request clarification or add additional context in comments.

2 Comments

My input is a .CSV file with the first line listing column names. Then why do I need to specify it twice?
That's how it works. You need to specify the columns in the SQL and use the IGNORE parameter to have it skip the first line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.