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

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    |                |
+---------------+-------------+------+-----+---------+----------------+

最佳答案

尝试:

$ 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)"

关于mysql - 加载infile语句会引发错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48059096/

10-13 07:47