gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:58:54 25 4
gpt4 key购买 nike

    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/

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