Solved

MySQL Load Data Infile Dates are all zeros

Posted on 2014-11-09
8
582 Views
Last Modified: 2014-11-16
I am using the Load Data Infile process to load large data files.  The columns that are supposed to be dates are coming up all zeros.  How can i make sure that the dates stay proper dates?

LOAD DATA INFILE "C:\\mydatafile.txt"
INTO TABLE data_test
COLUMNS TERMINATED BY X'7F'
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'

Open in new window

0
Comment
Question by:theideabulb
  • 4
  • 2
  • 2
8 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40431701
Can you provide sample(s) of the file(s)?

(or look at it this way: "How do we know what is in the files?")
0
 

Author Comment

by:theideabulb
ID: 40431723
Here is what it looks like


111370110043LEGO Star Wars Anakin Skywalker grown up with cape from  7113 - NKH NLJ01-OCT-14 12:19:45122711900608.9920Y

111456103707LEGO Star Wars - 2 Rare Original Printed Leg Stormtroopers - Excellent - 726401-OCT-14 08:14:02257119006048.0010Y

Open in new window


You don't really see the delimiter in a pasted example
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40431768
This might help. I placed those 2 rows into Notepad++, this is what it looks likedelimiters visible
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:theideabulb
ID: 40431908
Yes those breaks are correct for the columns of data
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 40440020
Hi!

Can you post the describe table output for the table data_test ?

Regards,
      Tomas Helgi
0
 

Author Comment

by:theideabulb
ID: 40440035
all the table data looks good except for the date.  that looks like

0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 500 total points
ID: 40440111
Hi!

If your data_test table has a column with the Date datatype which should hold your imported date values
then you need to add this line in your LOAD command
SET c4 = STR_TO_DATE(@c4,'%d-%b-%y %H:%i:%s')
like this

LOAD DATA INFILE "C:\\mydatafile.txt"
INTO TABLE data_test
COLUMNS TERMINATED BY X'7F'
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
  (C1, C2,C3,C4,C5,....)
SET c4 = STR_TO_DATE(@c4,'%d-%b-%y %H:%i:%s');

where c4 is the name of the date field and '%d-%b-%y %H:%i:%s' should correspond to the dateformat you have in the datafile.

http://dev.mysql.com/doc/refman/5.5/en/load-data.html
Regards,
      Tomas Helgi
0
 

Author Closing Comment

by:theideabulb
ID: 40445890
Thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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