Solved

MySQL Load Data Infile Dates are all zeros

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

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 49

Expert Comment

by:PortletPaul
ID: 40431768
This might help. I placed those 2 rows into Notepad++, this is what it looks likedelimiters visible
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

688 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