简体   繁体   中英

Importing .CSV file to mysql database

I have .csv file which I want to import to my database using the SQL syntax. This is how my .csv file looks like:

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

So I ran this code in my SQL syntax:

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. Therefore you have to use

LINES TERMINATED BY '\r\n'

instead:

从CSV导入值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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