Import CSV file to MySQL | MySQL Import CSV

This below example shows you how to use the LOAD DATA INFILE statement to import CSV file into MySQL table.

The LOAD DATA INFILE statement allows you to read data from a text file and import the file’s data into a database table very fast.

Before importing the file, you need to complete the following steps :

1) Data Import table should be created
2) CSV Columns Should be match with the Database Table.
3) Access required to execute the query

LOAD DATA INFILE ‘<<CSV File Name>>’
INTO TABLE <<Table Name>>
FIELDS TERMINATED BY ‘,’
ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n’
IGNORE 1 ROWS

Example :-

LOAD DATA INFILE ‘f:/LeadsDetails.csv’
INTO TABLE oldleads
FIELDS TERMINATED BY ‘,’
ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n’
IGNORE 1 ROWS

Advertisements