1

我将 csv 文件内容放入数据库中。当我在命令下手动运行时..它工作正常..但是当我在单个查询下方输入命令提示符时,它没有运行。

mysql -uuser -ppassword -hlocalhost -e "LOAD DATA INFILE "C:\csvfile.csv" 
INTO TABLE test.LoadedEmployee FIELDS TERMINATED BY "," ENCLOSED BY '' 
ESCAPED BY '\\' LINES TERMINATED BY "\n" STARTING BY ''"

仅供参考 .. 有效的手动语法:

mysql -uuser -ppassword -hlocalhost 
LOAD DATA INFILE "C:\csvfile.csv" INTO TABLE test.LoadedEmployee 
FIELDS TERMINATED BY "," ENCLOSED BY '' ESCAPED BY '\\' 
LINES TERMINATED BY "\n" STARTING BY ''
4

2 回答 2

0

如果要加载 CSV 文件,请尝试以下操作:仅供参考,这将忽略第一行 - 标题。

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
于 2012-10-29T06:18:19.673 回答
0

尝试这个:

load data local infile 'urfile.csv' into table yourtablefields terminated by ','
enclosed by ''  ESCAPED BY '\\'  lines terminated by '\n'
(col1, col2, col3...)

这里把实际的列名放在上面脚本的最后。也把这个脚本放在一个 .bat 文件中并将它保存在你的 .csv 文件所在的位置。现在打开命令提示符并导航到安装 mysql 的目录那里运行批处理文件。

于 2012-10-29T06:48:59.467 回答