Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a CSV File -- Getting Problems

Status
Not open for further replies.

chrisck

Technical User
Jan 4, 2003
3
GB
Hi all

I have got a database with 1 table and 16 fields, I am trying to import a csv file into this to populte all the fields however when I import it all the data is going into 1 field, how can I go about getting this to split it all into the required fields without re-writing the entire thing.

Any help would be grealty appreciated.

Cheers

CK
 
Just found your post.

Before attempting this make sure that the data in your .csv file is in the order as it will appear in the table.

When you write your load command it should look something like this:

mysql> load data infile 'yourfile.csv' into table tablename fields terminiated by ',';

This is presumming that you have the .csv file in the data directory for the given database.

The above command line tells MySQL to load the data from the specified file into a given table and, it also tells it that the data in your .csv file is separated by commas. This will ensure that the data makes it to the corresponding fields in the table. (see first paragraph above)

Make sure that your .csv file contains the same number of fields as the table has and if your primary key is an auto increment, that the .csv file field that corresponds to the table field be populated with an '/N'. Example below:

field1 field2 field3 field4
/N data data data

this is because if the auto increment field is populated going in you will get an error on the load. At least that's the experience I had.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top