2

Consider a table to store SSN and DOB.

CREATE TABLE fbi
(
     ssn BIGINT, 
     dob DATE
)

Data was loaded into the table:

LOAD DATA LOCAL INFILE C:\test.csv
INTO TABLE fbi
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';


SELECT * FROM fbi;

It is showing null values for DOB. I don't understand the error.

"ssn","dob"
  5,"1952-11-15"
  6,"1973-12-23"
 6,"1951-12-23"
 1,"1962-03-21"
7
  • Please post some of the sample data in your CSV (but please censor the the ssn field first!!!) Commented Oct 10, 2010 at 4:53
  • can you post your test.csv file? Commented Oct 10, 2010 at 4:56
  • 1952-11-16- dob is in this mannner Commented Oct 10, 2010 at 4:56
  • @sphipls: Do you have that trailing dash after the day or is that a typo in your comment? The dash should not be there and would definitely cause a problem. Commented Oct 10, 2010 at 4:57
  • @Asaph, what are you referring to? Commented Oct 10, 2010 at 5:01

1 Answer 1

3

It most likely has to do with the date formatting in your csv file. MySQL likes dates in the format yyyy-mm-dd. e.g. 2010-10-09. You might be able to get more information by issuing the following command in the MySQL command console immediately after your import:

show warnings;

UPDATE:

I see that your date field is quoted. If you have a quoted date, you'll need to tell MySQL that by adding OPTIONALLY ENCLOSED BY '"' to your import command (see MySQL manual for LOAD DATA INFILE). Try this:

LOAD DATA LOCAL INFILE C:\test.csv
INTO TABLE fbi
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';

BTW: I hope those SSN's you've posted are fake or mangled in some unrecoverable way.

Sign up to request clarification or add additional context in comments.

5 Comments

plz see the edited part of the question...so I have to do that now?
@shilps: It'll still be in the revision history of the question unfortunately. I'll flag this question for review by an admin.
well, I got the data from the HW that I got from my school.I dont think, there is any problem.
Oh, so those were not real social security numbers?
Ok, that's good. Unfortunately, I already flagged this question for moderator review.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.