Upload comma seperated values (CSV) into a MySQL database

From CodeCodex

Revision as of 21:34, 1 January 2007 by WikiSysop (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implementations[edit]

The field below would load a CSV file into a MySQL database.

  • /path/import.csv: The path and filename to upload
  • test_table: The table to upload into
  • ,: the character that separates the fields
  • \n: the character that separates the records
  • field1: the name of the field in the database to import the first field in the csv into.
LOAD DATA LOCAL INFILE '/path/import.csv'
INTO TABLE test_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, filed2, field3);