加载infile语句会引发错误

时间:2018-01-02 10:16:51

标签: mysql shell

我有一个表格,我试图从文本文件中插入数据,但它会引发一些错误 命令是

mysql -u user -p<pwd> -h <server> --local-infile bsm -sse LOAD DATA LOCAL INFILE '/tmp/file.txt' INTO table test_jan2 FIELDS terminated by '|' LINES terminated by '\n' (value1,value2,value3) set id = NULL;

它抛出的错误是

bash: syntax error near unexpected token `('

表结构是

+---------------+-------------+------+-----+---------+----------------+
| Field         | Type        | Null | Key | Default | Extra          |
+---------------+-------------+------+-----+---------+----------------+
| id            | int(11)     | NO   | PRI | NULL    | auto_increment |
| value1      | varchar(50) | YES  |     | NULL    |                |
| value2    | varchar(50) | YES  |     | NULL    |                |
| value3 | varchar(50) | YES  |     | NULL    |                |
| date_created  | varchar(50) | YES  |     | NULL    |                |
+---------------+-------------+------+-----+---------+----------------+

1 个答案:

答案 0 :(得分:1)

尝试:

$ mysql -u user -p<pwd> -h <server> --local-infile bsm -e \
   "LOAD DATA LOCAL INFILE '/tmp/file.txt'
    INTO table test_jan2
    FIELDS TERMINATED BY '|'
    LINES TERMINATED BY '\n'
    (value1,value2,value3)"