Load csv file data into MySQL table

Suppose we have a device table along with following columns.
id(integer),device(varchar),device_data(varchar).

Now suppose you want to upload data from a device.csv file like given below.
---------------------------------------------------
"id","device","device_data"
"1","A1","this is test device, model-11"
"2","A2","this is test device, model-12"
"3","A3","this is test device, model-13"
"4","A4","this is test device, model-14"
----------------------------------------------------

Use following command to insert these values from csv file to table with casting id value from text to integer.


LOAD DATA INFILE 'D:\device.csv' INTO TABLE device 
FIELDS TERMINATED BY  ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(@id, device, device_data)
SET id= CONVERT( @id, UNSIGNED INTEGER ) ;

Comments

Popular posts from this blog

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

Upload csv file at Google Cloud Storage using java

Read Images from a xlsx file using Apache POI