Discussion Locked

Import via .sql file w a auto-increment

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm looking for a way to import data from a csv file into MySQL. I've found a script that gets me close but the problem I am having a problem with the auto increment field in my table.

The script I'm using simply looks for a file named flatfile.txt and reads it line by line using | as the delimiter and then builds a .sql file with the insert statments. Here's an example from the .sql file created by the script:

INSERT INTO database_table VALUES ("1","1","name","1","description","something else","100.00");

The first value corresponds to an auto incrementing field. I suspect i need a different Insert statement or somesort of variable for the value of the auto-increment field. Any ideas??

Thanks,
Eric

5 replies

by sgt_shultz

well, you won't need to insert anything into the autoincrement field, it will, well, autoincrement...

by ziqbalbh

You don't need to specify any value for autoincrement fields. Just omit that field and specify column names explicity, so that they could correspond with the values.

by ericrb

Thanks for the suggestions. The answer (for my case at least)was to enter NULL as the value for the auto increment value. Worked great.

This discussion is closed to new replies.