i want to import csv file into mysql.. something like:
load data local infile 'uniq.csv' into table tblUniq
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(uniqName, uniqCity, uniqComments)
http://www.tech-recipes.com/rx/2345/import_csv_file_directly_into_mysql/
but column names in csv and that in database table are different what should i do? i want to do it programmatically..
If you want to load only the first 7 characters of the last column from the CSV file into the uniqComments column of the table, then you can do something like this...
Not a problem. You can specify which CSV column gets imported into which database column.
LOAD DATA INFILE syntax
What I like to do when I find the INFILE syntax too complicated is use a graphical client like HeidiSQL to click together the proper column order (it has a graphical preview) and copy+paste the generated SQL query.
Try this, this is working fine for me.
The below statements import the data from csv file into users table.
Import CSV file into MySQL
You can create a script to parse your csv file and to put the data into db.
Something like: