我将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 ''"
FYI ..正在运行的手动语法:
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 ''
答案 0 :(得分:0)
如果您要加载CSV文件,请尝试以下操作:FYI这将忽略第一行 - 标题。
LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
答案 1 :(得分: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文件所在的位置。现在打开comman提示符并导航到你的mysql所在的目录从那里安装运行批处理文件。