Solved

MySQL Load Data Infile Dates are all zeros

Posted on 2014-11-09
8
579 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

803 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