[英]Error during Load data infile: Data truncated for column user_type at row 392. user_type is empty in row 393
load data infile "C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Table-2 events.csv"
into table events
fields terminated by ","
lines terminated by "\r\n"
ignore 1 lines
(user_id, occurred_at, event_type, event_name, location, user_type, device);
It repeatedly shows the Data truncated error.它反复显示数据截断错误。 Describing table shows that it is allowed to have null values.
描述表显示允许有 null 个值。 The datatype is double.
数据类型是双精度的。 At Row 393 onwards the column starts to have null values, which is what is the problem I guess.
从第 393 行开始,该列开始有 null 个值,我猜这就是问题所在。 How do I resolve this?
我该如何解决这个问题?
Initially the column user_type was the last column so I even tried rearranging (thinking its a newline character problem) but that did not resolve it.最初列 user_type 是最后一列,所以我什至尝试重新排列(认为它是换行符问题)但这并没有解决它。 I even changed the data type to int to see if it would help, and no it didn't
我什至将数据类型更改为 int 以查看是否有帮助,但没有
This is how it looks这是它的样子
Field![]() |
Type![]() |
Null ![]() |
---|---|---|
user_id![]() |
double![]() |
YES![]() |
occurred_at![]() |
text![]() |
YES![]() |
event_type![]() |
text![]() |
YES![]() |
event_name![]() |
text![]() |
YES![]() |
location![]() |
text![]() |
YES![]() |
user_type![]() |
double![]() |
YES![]() |
device![]() |
text![]() |
YES![]() |
This is how the csv file looks at around 392这就是 csv 文件在 392 左右的样子
11768,01-05-2014 08:05,engagement,home_page,France,3,macbook pro
11768,01-05-2014 08:05,engagement,like_message,France,3,macbook pro
11769,01-05-2014 02:37,signup_flow,create_user,United Kingdom,,lenovo thinkpad
11770,01-05-2014 06:07,signup_flow,create_user,Japan,,iphone 5s
11770,01-05-2014 06:07,signup_flow,enter_email,Japan,,iphone 5s
11770,01-05-2014 06:08,signup_flow,enter_info,Japan,,iphone 5s
11770,01-05-2014 06:08,signup_flow,complete_signup,Japan,3,iphone 5s
11770,01-05-2014 06:08,engagement,login,Japan,3,iphone 5s
11770,01-05-2014 06:09,engagement,like_message,Japan,3,iphone 5s
Empty values can be handled using input preprocessing see manual https://dev.mysql.com/doc/refman/8.0/en/load-data.html可以使用输入预处理处理空值,请参见手册https://dev.mysql.com/doc/refman/8.0/en/load-data.html
for example例如
load data infile 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\data.txt'
into table t
fields terminated by ','
lines terminated by '\r\n'
#ignore 1 lines
(user_id
, occurred_at, event_type, event_name, location, @user_type, device
)
set user_type=case when @user_type = '' then null else @user_type end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.