使用 Load Data Infile 将 CSV 导入 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4485754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Importing CSV to MySQL with Load Data Infile
提问by MarathonStudios
I'm trying to load a CSV file into MySQL, and I keep getting syntax errors:
我正在尝试将 CSV 文件加载到 MySQL 中,但我不断收到语法错误:
load data infile 'c:/worldminwage.csv' fields terminated by ',' enclosed
by '"' lines terminated by '\n' (YearlyWage, PercentGDP, Date
effective);
Can anyone help me get this working? Thanks.
谁能帮我解决这个问题?谢谢。
回答by Oswald
Valid syntax is LOAD DATA INFILE 'c:/worldminwage.csv' INTO TABLE tablename
.
有效的语法是LOAD DATA INFILE 'c:/worldminwage.csv' INTO TABLE tablename
.
You forgot to mention which table the data should go in. See LOAD DATA INFILE Syntax
你忘了提到数据应该放在哪个表中。参见LOAD DATA INFILE Syntax
回答by Chirag
I think This would be more batter
我认为这会更棒
LOAD DATA INFILE 'c:/worldminwage.csv' fields terminated by ',';
Because you will get rid of error like columns numbers are not matching in the .csv file and mysql table
因为您将摆脱 .csv 文件和 mysql 表中列号不匹配等错误