mysql - 将 CSV 文件放入 MySQL 时出现问题

标签 mysql csv

    Query: 

    LOAD DATA LOCAL INFILE 'actors.csv' 
    INTO TABLE Actors 
    FIELDS TERMINATED BY ','  
    ENCLOSED BY '"' 
    LINES TERMINATED BY '\n' 
    IGNORE 1 LINES 
    (ACTOR_ID, FNAME, LNAME);

CSV File: 
        ACTOR_ID, FNAME, LNAME
        "66666","Billy","Lou"
        "77777","Sally","Lou"
        "88888","Hilly","Lou"

        mysql> describe Actors;
            +----------+-------------+------+-----+---------+-------+
            | Field    | Type        | Null | Key | Default | Extra |
            +----------+-------------+------+-----+---------+-------+
            | ACTOR_ID | char(5)     | NO   | PRI |         |       |
            | FNAME    | varchar(20) | NO   |     | NULL    |       |
            | LNAME    | varchar(20) | NO   |     | NULL    |       |
            +----------+-------------+------+-----+---------+-------+

            > The output after running query:

            | 10047    | Shirley     | Jones         |
            | 10048    | Andre       | Vippolis      |
            | 66666    | Billy       | Lou"
            "77777  |
            | 88888    | Hilly       | "Lou"
                   |
            +----------+-------------+---------------+

I am trying to put a CSV file into my database. I've gotten the query from a MySQL tutorial (except put the values I have in there). When I run the query, My data is not properly inserted. I already have 2 rows inserted (10047, 10048) and then I try to put the data from the CSV file in, but it does not go in properly. It seems that the quotations are not being read properly. But the statement ENCLOSED BY '"' should handle the quotations. What am I doing wrong here?

最佳答案

之间好像有\r

"Lou"
        "77777"

而不是\n

使用文本编辑器来纠正此问题。

找到相关so post

关于mysql - 将 CSV 文件放入 MySQL 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42583920/

相关文章:

java - 我可以从哪些地方了解更多有关 API 的信息?

php - 使用 Javascript 的 PHP 中的第一个下拉框不会保留我的选择

python - 无法导入csv文件进行协作?

python - 在写入 csv 文件时防止字符串以逗号分隔

MySQL 基本查询耗时特别长 - 解释计划看起来不错

mysql - 选择平均投票但使用 mysql 忽略前 5% 和后 5% 的选票

MySQL Select with Inner Join, Limit only first

c - 在 C 中读取 .csv 文件

javascript - 使用 d3.js (v5) 读取没有标题的 csv

excel - 如何将 Excel 中的 CSV 字段分隔到单独的框中