【问题标题】:Why am I obtaining this error message trying to import a .csv file into a MariaDB table?为什么我在尝试将 .csv 文件导入 MariaDB 表时收到此错误消息?
【发布时间】:2020-06-14 04:23:33
【问题描述】:

我正在尝试将 .csv 文件内容导入到 Maria DB 表中,但遇到了一些困难。我正在使用 Linux Ubuntu 环境。

我有以下情况。这是我的状态表:

MariaDB [Delphys]> describe Status;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| StatusID    | int(11)      | NO   | PRI | NULL    | auto_increment |
| Status      | char(1)      | YES  |     | NULL    |                |
| StatusGroup | char(3)      | YES  |     | NULL    |                |
| text        | varchar(255) | YES  |     | NULL    |                |
| TestText01  | varchar(255) | YES  |     | NULL    |                |
| TestText02  | varchar(255) | YES  |     | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
6 rows in set (0.106 sec)

这是我试图导入上一张表的文件的内容:

1;A;ABC;Existing sensors, already linked to DCS/DeltaV;Defalt value;Simulated input value
2;B;ABC;Existing sensors, already linked to DCS to be linked to DeltaV;Simulated value;Simulated input value
3;C;ABC;Sensors to be installed and linked to DCS/DeltaV;Simulated value;Simulated input value
4;D;D  ;Calculated Value without Model and GPA;expected result without Model and GPA;expected result without Model and GPA
5;E;E  ;Calculated Values after Establishment of Engine Model and GPA;expected result after Establishment of Engine Model and GPA;expected result after Establishment of Engine Model and GPA

我在 MariaDB 控制台中执行了以下命令,我收到以下错误消息:

MariaDB [Delphys]> LOAD DATA INFILE '/var/lib/mysql/Status.csv'
    -> INTO TABLE Status
    -> FIELDS TERMINATED BY ';' 
    -> LINES TERMINATED BY '\n'
    -> ;
ERROR 1366 (22007): Incorrect integer value: '??1' for column `Delphys`.`Status`.`StatusID` at row 1

一个疑问是我的 .csv 文件是由可能以不同方式处理换行符的 Windows 机器生成的(但对我来说似乎很奇怪)。

怎么了?我错过了什么?如何正确导入我的 .csv 文件?

【问题讨论】:

    标签: mysql database mariadb rdbms csv-import


    【解决方案1】:

    您缺少 INTO TABLE table,即 CSV 文件应插入到哪个表中。

    【讨论】:

    • 我使用“INTO TABLE ...”更正了命令,但现在我又遇到了另一个错误。我已经编辑了我的原始帖子
    • 听起来你在文件的开头有不可见的字符(很可能是 BOM,en.wikipedia.org/wiki/Byte_order_mark)。
    猜你喜欢
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 2022-01-08
    • 2017-01-17
    相关资源
    最近更新 更多