我试图通过shell提示符使用mysql加载。我想直接将csv文件加载到数据库中。
mysql -u root -p -h mysql -e "LOAD DATA INFILE 'Subscriber.csv' INTO TABLE temp_data FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'IGNORE 1 ROWS" psi
我得到错误ERROR 1083 (42000) at line 1: Field separator argument is not what is expected
下面是我的csv文件
misdn,city,age,gender771001244,MUTOKO,24,MALE771001286,MUTOKO,32,MALE771001334,MUTOKO,37,Male771001384,MUTOKO,36,MALE771001399,MUTOKO,25,Male771002873,HWEDZA,26,MALE771006412,HWEDZA,33,MALE771008125,MUTOKO,26,MALE771008127,HWEDZA,34,MALE771008142,HWEDZA,34,MALE771013473,MUTOKO,21,MALE771016262,MUTOKO,22,MALE771016360,MUTOKO,30,MALE771016701,MUTOKO,28,Male771017619,MUTOKO,33,Male771017822,MUTOKO,23,Male771019268,ZVISHAVANE,31,Male771024685,ZVISHAVANE,39,MALE
请帮忙,我做错什么了?

最佳答案

您使用了ENCLOSED BY '"',但您的字段根本不包含双引号。我认为你应该使用OPTIONALLY ENCLOSED BY '"'。请尝试此版本:

mysql -u root -p -h mysql -e "LOAD DATA INFILE 'Subscriber.csv'
    INTO TABLE temp_data
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'IGNORE 1 ROWS" psi

或者,如果您确定没有字段会有双引号,您可以完全删除ENCLOSED BY子句。

关于mysql - 第1行的错误1083(42000):使用mysql LOAD时,字段分隔符参数不是预期值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51247904/

10-13 01:48