从 LOAD DATA INFILE 查找 MySQL 错误

发布于 2024-08-06 22:33:23 字数 1001 浏览 5 评论 0原文

我正在 MySQL 中运行 LOAD DATA INFILE 命令,其中一个文件在 mysql 提示符下显示错误。

如何检查警告和错误?现在我唯一需要注意的是提示报告了 65,535 个导入警告。

mysql> use dbname;
Database changed
mysql> LOAD DATA LOCAL INFILE '/dump.txt'
    -> INTO TABLE table
    -> (id, title, name, accuracy);
Query OK, 897306 rows affected, 65535 warnings (16.09 sec)
Records: 897306  Deleted: 0  Skipped: 0  Warnings: 0

如何让 mysql 显示这些警告是什么?我查看了错误日志,但找不到它们。运行“SHOW WARNINGS”命令仅返回 64 个结果,这意味着其余 65,000 个警告一定在其他地方。

2 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
3 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
4 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
6 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
7 |
+---------+------+--------------------------------------------------------------
--+
64 rows in set (0.00 sec)

我如何找到这些错误?

I am running a LOAD DATA INFILE command in MySQL and one of the files is showing errors at the mysql prompt.

How do I check the warnings and errors? Right now the only thing I have to go by is the fact that the prompt reports 65,535 warnings on import.

mysql> use dbname;
Database changed
mysql> LOAD DATA LOCAL INFILE '/dump.txt'
    -> INTO TABLE table
    -> (id, title, name, accuracy);
Query OK, 897306 rows affected, 65535 warnings (16.09 sec)
Records: 897306  Deleted: 0  Skipped: 0  Warnings: 0

How do I get mysql to show me what those warnings are? I looked in the error log but I couldn't find them. Running the "SHOW WARNINGS" command only returned 64 results which means that the remaining 65,000 warnings must be somewhere else.

2 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
3 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
4 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
6 |
| Warning | 1366 | Incorrect integer value: '' for column 'accuracy' at row 2038
7 |
+---------+------+--------------------------------------------------------------
--+
64 rows in set (0.00 sec)

How do I find these errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅唱々樱花落 2024-08-13 22:33:23

MySQL SHOW WARNINGS 命令仅显示警告的子集。您可以通过修改参数 max_error_count 来更改显示的警告限制。

The MySQL SHOW WARNINGS command only shows you a subset of the warnings. You can change the limit of warning shown by modifying the parameter max_error_count.

往事风中埋 2024-08-13 22:33:23

出现这么多错误表明您使用了错误的分隔符或无关的引号,导致 MySQL 从您的输入中读取错误的列。

您可以通过

[{FIELDS | COLUMNS}
    [TERMINATED BY 'string']
    [[OPTIONALLY] ENCLOSED BY 'char']
    [ESCAPED BY 'char']
]
[LINES
    [STARTING BY 'string']
    [TERMINATED BY 'string']
]

在表名之后和列列表之前添加来解决此问题。

类似于:

加载数据本地INFILE'/dump.txt'
INTO TABLE 表
以 ' ' 结尾的字段(可选用 '"' 括起来)
(id、标题、姓名、准确性);

默认情况下,如果您不指定此项,MySQL 将使用制表符来终止字段。

Getting that many errors suggests that you have the wrong delimiter or extraneous quote marks that are making MySQL read the wrong columns from your input.

You can probably fix that by adding

[{FIELDS | COLUMNS}
    [TERMINATED BY 'string']
    [[OPTIONALLY] ENCLOSED BY 'char']
    [ESCAPED BY 'char']
]
[LINES
    [STARTING BY 'string']
    [TERMINATED BY 'string']
]

after the tablename and before the column list.

Something like:

LOAD DATA LOCAL INFILE '/dump.txt'
INTO TABLE table
fields terminated by ' ' optionally enclosed by '"'
(id, title, name, accuracy);

By default, if you don't specify this, MySQL expects the tab character to terminate fields.

小鸟爱天空丶 2024-08-13 22:33:23

数据文件中可能存在空白条目,并且目标表不允许空值,或者相​​关字段没有有效的默认值。

我会检查该表是否有默认的准确度 - 如果没有,请将其设置为零并查看是否可以清除错误。

或者,您可以使用“awk”或类似的方法预处理文件,并确保所有行中的准确度字段都有有效的数值。

There could be a blank entry in the data file, and the target table doesn't allow null values, or doesn't have a valid default value for the field in question.

I'd check that the table has a default for accuracy - and if it doesn't, set it to zero and see if that clears up the errors.

Or you could pre-process the file with 'awk' or similar and ensure there is a valid numeric value for the accuracy field in all rows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文