[英]LOAD DATA INFILE error: #1265 - Data truncated for column X at row 1
[英]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);
它反复显示数据截断错误。 描述表显示允许有 null 个值。 数据类型是双精度的。 从第 393 行开始,该列开始有 null 个值,我猜这就是问题所在。 我该如何解决这个问题?
最初列 user_type 是最后一列,所以我什至尝试重新排列(认为它是换行符问题)但这并没有解决它。 我什至将数据类型更改为 int 以查看是否有帮助,但没有
这是它的样子
场地 | 类型 | Null |
---|---|---|
用户身份 | 双倍的 | 是的 |
发生在 | 文本 | 是的 |
事件类型 | 文本 | 是的 |
事件名称 | 文本 | 是的 |
地点 | 文本 | 是的 |
用户类型 | 双倍的 | 是的 |
设备 | 文本 | 是的 |
这就是 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
可以使用输入预处理处理空值,请参见手册https://dev.mysql.com/doc/refman/8.0/en/load-data.html
例如
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.