Solved

MySQL Load Data Infile Dates are all zeros

Posted on 2014-11-09
8
543 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
 

Author Comment

by:theideabulb
ID: 40431908
Yes those breaks are correct for the columns of data
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 24

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 24

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now