sumi
sumi

Reputation: 467

inserting data in mysql by text file

I have the following data in the text file

   Lat      Lon      Cls
   -89.75  -179.75   EF
   -89.75  -179.25   EF
   -89.75  -178.75   EF
   -89.75  -178.25   EF
   -89.75  -177.75   EF
   -89.75  -177.25   EF
   -89.75  -176.75   EF

and i have to insert in in the mysql database in the following table

CREATE TABLE IF NOT EXISTS `jos_lat_log` (
`Lat` text NOT NULL,
`Lon` varchar(255) NOT NULL,
`climatefamily` varchar(255) NOT NULL
);

i am using the following query to insert

LOAD DATA LOCAL INFILE 'C:\\Koeppen-Geiger-ASCII.txt' 
INTO TABLE `jos_lat_log` FIELDS TERMINATED BY '' LINES TERMINATED BY '\r\n';  

the above query is working but it is inserting data in only one column but i have to insert it in all three columes

Upvotes: 1

Views: 1326

Answers (2)

Matthew Sainsbury
Matthew Sainsbury

Reputation: 1488

if your fields are seperated by a space,

TERMINATED BY ' '

with a space between quotes

Upvotes: 2

Brian Glaz
Brian Glaz

Reputation: 15666

Your fields in the file are terminated by a space ' ', but you have listed '' in your query. Just change FIELDS TERMINATED BY '' to FIELDS TERMINATED BY ' '

Upvotes: 0

Related Questions