Solved

MySQL Load Data Infile Dates are all zeros

Posted on 2014-11-09
8
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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. …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

737 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