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
When you load data from file to a MySQL table, you might run into this error:
Data truncated for column 'column_name' at row #
That error means the data is too large for the data type of the MySQL table column.
Here are some common causes and how to fix:
1. Datatype mismatch.
First, check if the data type of the column is right for the input data. Maybe its defined length is smaller than it should be, or maybe there’s a misalignment that resulted in a value trying to be stored in a field with different datatype.
2. Wrong terminating character
If you manually insert each line into the table and it works just fine, the error occurs only when you load multiple lines, then it’s likely the command didn’t receive proper terminating character.
So check your file’s terminating character and specify it in the LOAD command
- If it’s terminated by a tab :
FIELDS TERMINATED BY 't'
- If it’s terminated by a comma
Then you’re good to go.
Need a good MySQL GUI? TablePlus provides a native client that allows you to access and manage MySQL and many other databases simultaneously using an intuitive and powerful graphical interface.
Download TablePlus for Mac.
Not on Mac? Download TablePlus for Windows.
Need a quick edit on the go? Download for iOS
I created a table in mysql like this :
create table if not exists data
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
execute_time DATETIME NOT NULL default current_timestamp,
db VARCHAR(25) NOT NULL,
book varchar(6),
`open` float(20,3) not null,
`close` float(20,3) not null)
and when I want to insert value into this table, it fails and show the exception as DataError: (1265, «Data truncated for column ‘open’ at row 1»)
and the values I want to insert into open is 3535929.559. I code the insert data in python like this:
insertData = """INSERT INTO {table_name} (execute_time,db,book,`open`,`close`) values
(%(execute_time)s,%(db)s,%(book)s,%(open)s,%(close)s)""" .format(table_name = settings["dumpTable"]["data"])
conn.cursor().executemany(insertData,data_in_dict)
conn.commit()
The most strange thing is when I insert the same value in MySQL workbench ,it went smoothly, the query is like this :
insert into data (db,book,`open`,`close`,execute_time) values ('au','book','3535929.559','1079339.851','2016-7-22');
But the data shown in the table is:
'5', '2016-07-05 00:00:00', 'au', 'book', '3535929.500', '1079339.875'
I think the problem maybe insertion from python is more restricted? Then how to set it to be less restricted? Any help would be appreciated!

This article demonstrates the possible reasons and solutions for an error, saying that Data is truncated for a column
in MySQL.
Fix Data is Truncated for a Column
Error in MySQL
Here, we will explore the possible reasons and solutions to get rid of an error saying MySQL data is truncated for a column
.
Data Is Too Large
There are some scenarios when we have to load the data from a file instead of inserting manually into the MySQL table. While loading, the Data truncated for a column 'columnName' at row #
error may occur. Why?
This is because the given data seems too big for a data type of the column in the MySQL table. For instance, you have a table where a value
attribute is of type text
which can only accommodate 65K characters of the provided data.
You will get this error when you insert data for the value
column that exceeds 65K.
To solve this problem, you need to change the type that can accept more data, such as MEDIUMTEXT
or LONGTEXT
, which can accommodate 16MB and 4GB. You can also find some optimization tips here.
We can also truncate the data using SET ANSI_WARNINGS OFF
and insert the records again, considering the maximum length of the column’s data type.
Invalid Data Is Passed
The Error Code: 1265. Data truncated for column 'a' at row 1
also occurs in MySQL if we try to insert invalid data.
For example, we have a table where the price
field is type float
and accepts the NULL
values. See the following:
#create a table named `prices`
CREATE TABLE prices (ID INT NOT NULL, price FLOAT NULL);
#insert the first record
INSERT prices VALUES (1, '');
Here, we insert an empty string in the price
column, a float
type that takes NULL
values. Remember, NULL
and ''
are not the same thing.
Still, if we try to insert an empty string in a column that takes NULL
values, it would generate the Error Code: 1265. Data truncated for column 'a' at row 1
. The simplest solution to this problem is passing the correct value of the right data type as required by the respective column of the price
table.
We can solve it by specifying the NULL
values explicitly instead of an empty string (''
) or do not even write the values for that particular column in the INSERT
statement. See the following snippet considering our example.
INSERT prices VALUES (1, NULL); #insert null explicitly
INSERT prices (ID) VALUES (2); #don't specify values for `price` column
Incorrect Terminating Character
If we insert every line manually in the MySQL table, everything goes well. The error occurs when we try to load more than one line at once and don’t get the terminating character properly.
To solve this, we need to check the terminating character of the file and specify in the LOAD
command as follows.
#if the terminating character is `tab`
FIELDS TERMINATED BY 't'
#if the terminating character is a `comma`
FIELDS TERMINATED BY ','
This is an article where the main discussion or its written to solve the error problem specified in the title of this article. The article is triggered upon inserting new rows to a table in a database which all the data are extracted fro another table located in another database. For more information, below is the actual output shown as an error message upon inserting new records :
user@hostname:~$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2537 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> insert into newdb.table1 from select * from olddb.table1; ERROR 1265 (01000): Data truncated for column 'column_name' at row 1 mysql>
The above SQL Query command, it is actually an SQL Query command executed in order to insert a new record in a table located in a database from another table located in other database. In order to solve it, one way to solve it is to actually set SQL_MODE to nothing. Below is the actual SQL_MODE value :
mysql> select @@SQL_MODE; +-------------------------------------------------------------------------------------------------------------------------------------------+ | @@SQL_MODE | +-------------------------------------------------------------------------------------------------------------------------------------------+ | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +-------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0,00 sec) mysql>
So, in order to set SQL_MODE to nothing, below is the configuration on it :
mysql> SET SQL_MODE=''; Query OK, 0 rows affected, 1 warning (0,00 sec) mysql>
To prove it whether it has already changed, in this context the value of SQL_MODE, below is another query command executed in order to preview the value of SQL_MODE :
mysql> select @@SQL_MODE; +------------+ | @@SQL_MODE | +------------+ | | +------------+ 1 row in set (0,00 sec) mysql>
After changing the value of SQL_MODE, just re-execute the query as shown below :
mysql> insert into newdb.table1 from select * from olddb.table1; Query OK, 59 rows affected, 118 warnings (0,05 sec) Records: 59 Duplicates: 0 Warnings: 118 mysql> quit Bye user@hostname:~$
#1 27.06.2011 21:53:34
- simple
- Активист
- Зарегистрирован: 25.11.2010
- Сообщений: 168
Warning 1265 при апдейте таблицы
Перешел на стандартную консоль mysql, до этого работал в клиенте heidisql. Так вот время от времени в клиенте вылазиет такое сообщение: Query Ok, 0 rows affected, 1 warnings (0.01 sec). Делаю show warnings; вылазиет вот такое…Note 1265 Data truncated for column ‘Quote’ at row 1. Хотя запрос все выполняет верно, хотелось бы знать возможную причину почему появляется это сообщение? В другом клиенте такого рода ошибок вообще не было а вот стандартный что то капризничает
Неактивен
#2 28.06.2011 13:32:42
- paulus
- Администратор
- Зарегистрирован: 22.01.2007
- Сообщений: 6740
Re: Warning 1265 при апдейте таблицы
Видимо, таки дело не в клиенте, а в том, что вставляете значение длиннее, чем ширина столбца.
Неактивен
#3 28.06.2011 15:06:17
- simple
- Активист
- Зарегистрирован: 25.11.2010
- Сообщений: 168
Re: Warning 1265 при апдейте таблицы
А эта ошибка может привести в дальнейшем к более серьезным ошибкам? Поле quote имеет тип данных decimal(5,2), в него записывается сумма всех цен деленное на кол-во сделок, т.е средняя цена, вот на этом поле и вылазиет эта ошибка 1265, только я не пойму как значение оказывается длинее поле то?
Неактивен
#4 28.06.2011 15:17:37
- simple
- Активист
- Зарегистрирован: 25.11.2010
- Сообщений: 168
Re: Warning 1265 при апдейте таблицы
А понял, при делении суммы цен иногда в дробная часть увеличивается на несколько цифр, наприме 90.0524125 отсюда и ошибка, спасибо форуму, буду исправлять этот «баг»
Неактивен
#5 28.06.2011 18:13:48
- paulus
- Администратор
- Зарегистрирован: 22.01.2007
- Сообщений: 6740
Re: Warning 1265 при апдейте таблицы
Если я правильно помню обозначения, в DECIMAL(5,2) не влезет 1265 — до точки
должно быть 5-2=3 символа.
Брр, перечитал, 1265 — это не то, что Вы пытаетесь вставить Но все равно, учтите.
Неактивен
After Upgrading from MySql 8.0.13 (compiled from sourcecode) to MySql 8.0.15, the MySql Server can not start.
Log:
2019-02-12T10:09:52.275336Z 1 [ERROR] [MY-013178] [Server] Execution of server-side SQL statement 'INSERT INTO routines SELECT * FROM mysql.routines' failed with error code = 1265, error message = 'Daten abgeschnitten für Feld 'sql_mode' in Zeile 7'.
2019-02-12T10:09:52.302630Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-02-12T10:09:52.302856Z 0 [ERROR] [MY-010119] [Server] Aborting
«Daten abgeschnitten für Feld» means «Data truncated for field» — its a German version …
Table checker does not find any errors — how can I solve this problem ?
asked Feb 12, 2019 at 11:13
The error says it all:
The command
INSERT INTO routines SELECT * FROM mysql.routines
had its data truncated for field sql_mode
on line 7 of the SELECT.
So in the 7th row returned by SELECT * FROM mysql.routines
,
the column sql_mode
of table routines
was defined as too small to receive
the value from the matching column of the table mysql.routines
.
answered Feb 12, 2019 at 13:16
harrymcharrymc
431k30 gold badges495 silver badges876 bronze badges
1
I found the solution myself. On the old mysql 8.0.13 server I corrected the field SQL_MODE for one of the stored procedures, what happened to be too long.
SELECT * FROM INFORMATION_SCHEMA.ROUTINES;
I found some (old) stored procedures I did not need anymore, and the entries in field SQL_MODE of one of that stored procedures were too long. After deleting that stored procedure, starting the new 8.0.15 server and «mysql_upgrade» everything is fine, the server can now start without any errors.
answered Feb 13, 2019 at 16:06