Import CSV File into MySQL Table,Import CSV to MYSQL

LOAD DATA INFILE statement to import CSV file into MySQL table.

Example:
CREATE TABLE statement to create the Test table as follows:
CREATE TABLE Test (
    id INT NOT NULL AUTO_INCREMENT,
    Name VARCHAR(255) NOT NULL,
    DateCol DATE NOT NULL,
    Amt DECIMAL(10 , 2 ) NULL,
    PRIMARY KEY (id)
);



Sample CSV
id,Name,DateCol,Amt
1,"John",20180101,200
2,"Peter",20170101,300

Load Csv DATA
LOAD DATA LOCAL INFILE 'c:/Uploadfile.csv' 
INTO TABLE Test 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

Result:

Post a Comment

0 Comments