-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?

BlueSkies
  • 109
  • 8
  • I'm voting to reopen this, since the other question https://stackoverflow.com/questions/4202564/how-to-insert-selected-columns-from-a-csv-file-to-a-mysql-database-using-load-da has no accepted answer and an incorrect answer before the correct one. Close again if you disagree. – ysth Dec 06 '19 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. – Shadow Dec 06 '19 at 22:15

1 Answers1

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

ysth
  • 96,171
  • 6
  • 121
  • 214
  • My input is a .CSV file with the first line listing column names. Then why do I need to specify it twice? – BlueSkies Dec 06 '19 at 21:25
  • 1
    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 – ysth Dec 06 '19 at 21:29