我正在尝试将文件加载到云主机上的mysql表中,但它给我一个语法错误。我的mysql版本是5.5.31。
mysql -u ykd202 -p -e' LOAD DATA INFILE" home / folks / kosh / intx.csv"进入TABLE历史记录列由','选择性地包含在'"' ESCAPED BY'"'线路终止于' \ n' IGNORE 1 LINES;' F2014
在上面的语句中,f2014是数据库名称。我得到的错误是
Enter password:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' optinally enclosed by ' escaped by ' lines terminated by n ignore 1 lines' at line 1
答案 0 :(得分:1)
您发布了以下代码:
mysql -u ykd202 -p -e 'LOAD DATA INFILE "home/folks/kosh/intx.csv" into TABLE history COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATE BY '\n' IGNORE 1 LINES;' f2014
但是,您的错误消息自相矛盾:
第1行的错误1064(42000):您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,使用“在第1行的'忽略1行'后面的'转换'行'附近使用
1a)错误的一部分:optinally enclosed by
- 错误的“optinally”,它应该是“可选的”。
1b)部分代码:OPTIONALLY ENCLOSED BY '"'
然后 ...
2a)部分错误:lines terminated by n
和
2b)部分代码:LINES TERMINATE BY '\n'
- 在TERMINATE结束时缺少D
,应该读作TERMINATED。
所以我会在这里说你需要修改你的代码:
mysql -u ykd202 -p -e 'LOAD DATA INFILE "home/folks/kosh/intx.csv" into TABLE history COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;' f2014
修改强>
另请尝试:
mysql -u ykd202 -p -e "LOAD DATA INFILE 'home/folks/kosh/intx.csv' into TABLE history COLUMNS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;" f2014