Archives

All posts for the month September, 2012

Import CSV file Into MYSQL DB

Published September 18, 2012 by Siva

System administrators sometime automate CSV file in to MYSQL DB with requested structure.

Login into mysql as root user, And execute the Follwing query with correct your path & tour fileds.
load data local infile ‘/tmp/file.csv’ into table mytable fields terminated by ‘, ‘
lines terminated by ‘\n’
(field,filed1,filed2,filed3,field4,filed5);

The query load the data from file to mysql talble called mytable.
I assume csv file contain , seperated. For Eg
# cat /tmp/file.csv
1,siva,CBE,TN,INDIA
2,kumar,CBE,TN,INDIA

Once everything done use cron to automate. to write simple script for automate this.

Advertisements