Load CSV file to MySQL

April 9, 2008 by
Filed under: mysql 

In many cases it is very convenient to import CSV files directly into the database, so it can be analyzed, referred to and other useful actions. MySQL’s can easily load tables from files, using the LOAD DATA INFILE command, but its default separators do not match the CSV format. Here is the LOAD command, fitted to load CSV files:

LOAD DATA INFILE '/tmp/file.csv'
INTO TABLE the_table
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
Share

Comments

Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!