Home > Net >  How to import data from CSV file to MySql table only for selected columns and CSV has both values en
How to import data from CSV file to MySql table only for selected columns and CSV has both values en

Time:07-01

I have tried using this commands

LOAD DATA LOCAL INFILE '/home/cs/Documents/abc.csv' 
INTO TABLE whatsappmessages 
FIELDS TERMINATED BY ','  
IGNORE 1 ROWS  
(number,@Number,message,@Message) 
set createdtime=now();

It is inserting number column value correctly , But in message column few data which are enclosed with ""(double quotes) and after the comma(,) string is taking(ie: logo and details. Click https://xxxx.co/xyzop now!) and inserting not the full value , but without double quotes empty string is inserting(ie: second line) .

This is the CSV file content i have

1111111111,"MARKET YOUR STORE! Customize xxxxxx latest emailer featuring aaaa cccc with your store name, logo and details. Click https://xxxx.co/xyzop now!"
2222222222,MARKET YOUR STORE! By sharing xxxxxx stunning collection featuring aaaa cccc with your consumer database. Click https://xxxx.co/xyzop now!
2222222222,"MARKET YOUR STORE! Customize xxxxxx latest emailer featuring aaaa cccc with your store name, logo and details. Click https://xxxx.co/xyzop now!"
3333333333,MARKET YOUR STORE! By sharing xxxxxx stunning collection featuring aaaa cccc with your consumer database. Click https://xxxx.co/xyzop now!

Anyone knows how to solve this please help me out, Thanks!

CodePudding user response:

try this

LOAD DATA LOCAL INFILE '/home/cs/Documents/abc.csv' 
INTO TABLE whatsappmessages 
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '"' 
LINES TERMINATED BY '\r\n'
IGNORE 1 ROWS  
(number,message) 
set createdtime=now();
  • Related