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 ) ;
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
Post a Comment