简体   繁体   English

将.CSV文件导入MySQL数据库

[英]Importing .CSV file to mysql database

I have .csv file which I want to import to my database using the SQL syntax. 我有一个要使用SQL语法导入到数据库的.csv文件。 This is how my .csv file looks like: 这是我的.csv文件的样子:

"john"
"james"
"peter"
"andrew"
"harry"
"king"
"hanny"
"charles"

So I ran this code in my SQL syntax: 所以我用我的SQL语法运行了这段代码:

LOAD DATA LOCAL INFILE 'C:/file.csv' INTO TABLE table FIELDS TERMINATED BY '' ENCLOSED BY '"' LINES TERMINATED BY '\n' (names)

But this is what I get when inserted: 但这是我插入时得到的:

john"
"james"
"peter"
"andrew"
"harry"
"king"
"hanny"
"charles

Please how do I make each name to be inserted in each row 请如何将每个名称插入每一行

Since you are working on Windows, the rows in your CSV are delimited by a carriage return \\r and an escape sequence \\n. 由于您使用的是Windows,因此CSV中的行由回车符\\ r和转义序列\\ n分隔。 Therefore you have to use 因此,您必须使用

LINES TERMINATED BY '\r\n'

instead: 代替:

从CSV导入值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM