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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: