user-img
mysql - error 1265. Data truncated for column when trying to load data from txt file - Stack Overflow

I have table in mysql table table looks like

create table Pickup
(
PickupID int not null,
ClientID int not null,
PickupDate date not null,
PickupProxy  varchar (40) ,
PickupHispanic bit default 0,
EthnCode varchar(2),
CategCode varchar (2) not null,
AgencyID int(3) not null,

Primary Key (PickupID),
FOREIGN KEY (CategCode) REFERENCES Category(CategCode),
FOREIGN KEY (AgencyID) REFERENCES Agency(AgencyID),
FOREIGN KEY (ClientID) REFERENCES Clients (ClientID),
FOREIGN KEY (EthnCode) REFERENCES Ethnicity (EthnCode)
);

sample data from my txt file 
1065535,7709,1/1/2006,,0,,SR,6
1065536,7198,1/1/2006,,0,,SR,7
1065537,11641,1/1/2006,,0,W,SR,24
1065538,9805,1/1/2006,,0,N,SR,17
1065539,7709,2/1/2006,,0,,SR,6
1065540,7198,2/1/2006,,0,,SR,7
1065541,11641,2/1/2006,,0,W,SR,24

when I am trying to submit it by using

LOAD DATA INFILE 'Pickup_withoutproxy2.txt' INTO TABLE pickup;

it throws error

Error Code: 1265. Data truncated for column 'PickupID' at row 1

I am using MySQL 5.2

up vote 12 down vote accepted

This error means that at least one row in your Pickup_withoutproxy2.txt file has a value in its first column that is larger than an int (your PickupId field).

An Int can only accept values between -2147483648 to 2147483647.

Review your data to see what's going on. You could try to load it into a temp table with a varchar data type if your txt file is extremely large and difficult to see. Easy enough to check for an int once loaded in the database.

Good luck.

  • 6
    or first row is null – zb' Feb 8 '13 at 1:41
  • @eicto -- I wondered that too since it said Row 1 :) – sgeddes Feb 8 '13 at 1:42
  • But it cannot be larger than int because max int is 10 digits number i use only 7 digits number. Table is really big more than 128000 records – Andrey Feb 8 '13 at 3:57
  • @AndreyIvanov -- double check your first row (and last). As I mentioned, you should be able to import into another table changing that field to a varchar and see what happens. I suspect another error, but different int column. Let me know. – sgeddes Feb 8 '13 at 3:59
  • Ok will try tomorrow morning and will leth you know. – Andrey Feb 8 '13 at 4:04

You're missing FIELDS TERMINATED BY ',' and it's assuming you're delimiting by tabs by default.

I have met this problem with a column that has ENUM values('0','1').
When I was trying to save a new record, I was assigning value 0 for the ENUM variable.

For the solution: I have changed ENUM variable value from 0 to 1, and 1 to 2.

I had this issue when trying to convert an existing varchar column to enum. For me the issue was that there were existing values for that column that were not part of the enum's list of accepted values. So if your enum will only allow values, say ('dog', 'cat') but there is a row with bird in your table, the MODIFY COLUMN will fail with this error.

  • it is post from 2013 :) but thanx :) i think problem was in data format :) but i dont remember – Andrey Oct 2 at 19:31
  • @Andrey Sorry about the necropost but I thought people might find this useful anyway, as both the question and the answers are still valid and helpful! – Liam Mayfair Oct 2 at 19:33
  • no problem , thanks :) i understand that it can still be useful :) – Andrey Oct 2 at 20:00

This error can also be the result of not having the line,

FIELDS SPECIFIED BY ','

(if you're using commas to separate the fields) in your MySQL syntax, as described in this page of the MySQL docs.

  • 2
    TERMINATED, not SPECIFIED – Jealie May 10 '17 at 17:39

I had same problem. I wanted to edit ENUM values in table structure. Problem was because of rows that was saved before and new ENUM values doesn't contain saved values.

Solution was updating old saved rows in MySql table.

Your Answer