1

I'm trying to import a CSV files into my MySQL table using the following query:

LOAD DATA INFILE 'C:\\machines.csv'
INTO TABLE `machines` 
CHARACTER SET latin1
FIELDS TERMINATED BY ','
  OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 0 LINES;

However it give the following error

1406- Data too long for column 'technicalInfo' at row 10334

It seems that the issue is that the row contains a character in the technicalInfo column.

Is it possible to remove/replace this character within the query?

(N.B. Obviously another solution would be to remove it from the csv file itself. The problem is that I am likely to be importing different versions of this file multiple times every day, so I'd rather build it in to the query.)

3
  • did you try mysqlimport utility? Commented Nov 10, 2011 at 11:15
  • does changing your character set` to utf-8` help? Commented Nov 10, 2011 at 11:17
  • @abhinav Thanks. Looks like it's supposed to be "utf8" (without the dash). Commented Nov 10, 2011 at 11:34

2 Answers 2

1

The problem is that the '⌀' character is not available in the latin1 character set and that is why you're getting the error. Can you change the character set to utf8 and see if you still experience the problem?

[1] MYSQL Error 1406 details: http://bugs.mysql.com/bug.php?id=18908

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

3 Comments

Hmm...now I'm getting the following error: 1366- Incorrect string value: '\xEF\xBB\xBF0-0...' for columm 'technicalInfo' at row 1
Also check that the machines table's character set is utf8 and not latin1.
The machines table is now set to utf8, but I still get the same error.
0

You can change or remove that symbol, e.g. -

LOAD DATA INFILE 'C:\\machines.csv'
INTO TABLE `machines` 
CHARACTER SET latin1
FIELDS TERMINATED BY ','
  OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 0 LINES
(column1, column2, @var1) -- specify column names here
SET column3 = REPLACE(@var1, '⌀', ''); -- replace it with '!'

1 Comment

This give me the following error: 1270- Illegal mix of collations (latin_swedish_ci,IMPLICIT),(utf8_general_ci,COERCIBLE),(utf8_general_ci,COERCIBLE) for operation 'replace'

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.