Tuesday, July 7, 2009

Importing CSV files into MySQL

One day, the computer world will agree on its line endings... Here is a code snippet for importing a CSV file into an already-constructed table in MySQL:

LOAD DATA INFILE 'C:\\Documents and Settings\\mrj35\\My Documents\\JISC_eAdmin_project\\New_sites\\Divinity\\staff_divisions.csv'
INTO TABLE tmp_names
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY "\r\n";

Query OK, 154 rows affected (0.00 sec)Records: 154 Deleted: 0 Skipped: 0 Warnings: 0

No comments: