import data

How can we import data in MySQL from CSV file

Run this SQL script either from a mysql console or from your favorite scripting language (PHP, PERL…)

LOAD DATA LOCAL INFILE ‘/path-to-file/dump_file.csv’
INTO TABLE table_name
FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
(Field_1, Filed_2, Field_3);

I believe the syntax is more than clear so I won’t bother explaining too much.

  • Share/Bookmark

Tags: , , , ,

Tuesday, April 22nd, 2008 MySQL, PHP No Comments