0

File : /DNC/myphones.csv CONTENTS:

Phone
5555555555
5555555556

SQL - LOAD DATA LOCAL INFILE '/DNC/myphones.csv' INTO TABLE test
LINES TERMINATED BY '\r\n'

What Comes back back is several warnings and a few skips and one Record makes it into the table a record of 2174563487 - Most of these digits don't exist in the data. Where is this coming from?

csv was created in MSOUTLOOK 2010, Also tried the above with a "test" file written in nano of the same contents.

Any help would be GREATLY appreciated.

UPDATE - Changing the Schema to a VARCHAR(255) Makes this work properly. Could it be reading the CSV file contents as a string instead of as integer? That would explain it not reading the values from the CSV but not where its getting the weird 217 #

Final Update. Since ill never perform mathematical operations on the phone number ive just decided to use a string instead. But thanks everyo e for your help

6
  • what is your "test" table schema? Commented Jun 3, 2016 at 16:15
  • Single Column "Phone" INT(255) NOT NULL PRIMARY KEY Commented Jun 3, 2016 at 16:19
  • "/r/n" is another issues, answer updated. Commented Jun 3, 2016 at 16:24
  • Did you sanitize your data into integer? A space, dash,etc will cause error and give you surprises. Otherwise, just store the field into VARCHAR and give it a unique ID. Commented Jun 3, 2016 at 16:41
  • Yes. The second test file i made with nano was just the phone numbers with no header. Id enter the # press enter, enter the other # then save Commented Jun 3, 2016 at 16:48

1 Answer 1

2

First, you schema only take integer, the header will cause server to spit error. If header not part of the data, why don't you skip it?

LOAD DATA LOCAL INFILE '/DNC/myphones.csv' INTO TABLE test 
  LINES TERMINATED BY '\r\n' 
  IGNORE 1 LINES;

Seconds, incorrect line terminated. They are different for Windows"\r\n" and Linux "\r". However, "/" vs "\" is only apply for folder , not newline/tab/return character.

Sign up to request clarification or add additional context in comments.

4 Comments

I will in the final draft. I'm going for a minimal coding approach in my testing so not typing that ignore 1 lines at the end for the 150+ times i've tried this saves a little bit of typing
Oops. The machine this is running on has no gui. I typed this in wrong when asking the question. will correct now.,
really, how much typing is omitted from the question? don't tell me you ommit CSV field enclose and delimiter. ;-D
None from the question.... I didn't define the field enclose or the delimiter because it isn't technically delimited, there is only one field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.