[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Import .csv to mySQL when there is an auto-increment on Primary Key

Posted on 2009-02-23
3
Medium Priority
?
4,689 Views
Last Modified: 2012-05-06
I want to import a .csv file into a mySQL database.  My first field is the ID field, which is the Primary Key, set to auto-increment.  I thought I could leave that field blank in the .csv and have the database take care of it.  I found out I was wrong.  How should that be handled?
0
Comment
Question by:DennisHacker
  • 2
3 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 23717681
How are you doing the import? If you use LOAD DATA, leave the ID field out of the field list, but list all the other fields.

http://dev.mysql.com/doc/refman/5.1/en/load-data.html
0
 

Author Comment

by:DennisHacker
ID: 23717706
Actually I was using the LOAD DATA feature built in to phpmyadmin.  You're right, I had that field listed in the list.  If the field is first in the database, and I leave it out of the .csv file, will the data import and just auto-increment the ID field, or do I have to put that field at the end?
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 23717748
Just leave out that field from the LOAD DATA and from the csv file. No need to put it at the end. If the table has 10 columns including the ID, the csv file should have 9 columns.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this article, we’ll look at how to deploy ProxySQL.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question