gpt4 book ai didi

mysql - 导入文件时出现错误 "1366 Incorrect integer value: ' 1'"

转载 作者:行者123 更新时间:2023-11-29 19:02:03 25 4
gpt4 key购买 nike

我正在尝试内联上传存储在 UTF-8 文本文件中的数据,但有两个问题。首先,该表目前没有设置主键,此时也没有设置自增或强制为空;加载所有数据后,第一列将成为预期的主键,此时将添加外键。

我收到以下错误:

25 row(s) affected, 1 warning(s): 1366 Incorrect integer value: '1' for column 'idtable_file' at row 1 Records: 25 Deleted: 0 Skipped: 0 Warnings: 1

尝试运行此命令时:

LOAD DATA LOCAL INFILE '/path' INTO TABLE sandr.table_file 
columns terminated by ','
LINES terminated by '\n'
(idtable_file, owner_id, folder_id, @modified_date, @created_date, size, filename)
SET modified_date = STR_TO_DATE(@modified_date,'%d/%m/%Y %T'),
created_date = STR_TO_DATE(@created_date,'%d/%m/%Y %T')

在此表上:

CREATE TABLE `table_file` (
`idtable_file` int(11) DEFAULT NULL,
`owner_id` int(11) DEFAULT NULL,
`folder_id` int(11) DEFAULT NULL,
`modified_date` datetime DEFAULT NULL,
`created_date` datetime DEFAULT NULL,
`size` int(11) DEFAULT NULL,
`filename` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

我做错了什么,但我刚刚开始使用 MySQL,所以我在黑暗中摸索了一些,对此有什么想法吗?另外,尽管上面的 SQL 查询在 PowerShell 中运行良好,但它是这样的:

LOAD DATA LOCAL INFILE '/path' INTO TABLE sandr.table_file 
columns terminated by ','
LINES terminated by '\n'

它爆炸了:

Exception calling "ExecuteNonQuery" with "0" argument(s): "Fatal error encountered during command execution."

如果我将调整添加到日期字段。

最佳答案

25 row(s) affected, 1 warning(s): 1366 Incorrect integer value: '1' for column 'idtable_file' at row 1 Records: 25 Deleted: 0 Skipped: 0 Warnings: 1

我也遇到过这个错误。需要注意的是

  • 这个错误显然是荒谬的(似乎是说“1”是一个整数,是一个不正确的整数值),并且
  • 它发生在第一行的第一列并且仅在那里

如果这两个条件成立,那么罪魁祸首很可能是一个隐藏的三字节序列,它正好位于您尝试加载的 SQL 文件的开头(称为 UTF8 字节顺序标记)。

在某些情况下,错误消息中的序列会被转义并以可识别的方式显示,例如 in this bug report 。在其他情况下,它作为值的一部分发送给用户:

Incorrect integer value: '###1'  ...

但是终端“吃掉”了 BOM,您看到的是(现在很荒谬的)错误

Incorrect integer value: '1' ...

要解决此问题,您需要使用能够删除字节顺序标记的编辑器(例如Notepad++)打开要导入的文件。

关于mysql - 导入文件时出现错误 "1366 Incorrect integer value: ' 1'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43798772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com