我正在尝试将一个文件加载到mysql中,得到的错误是error 3140(22032):invalid json text:“invalid value.”位于value for column的位置0。文件中的数据如下所示,
id,name,jfield1,jfield2
1,"A","{\"Key1\": 100,\"key2\": \"Abc\"}","{}"
2,"B","{\"Key1\": 101,\"key2\": \"Def\"}","{}"
我的table:
CREATE TABLE `test` (
`id` int(3) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL,
`jfield1` json NOT NULL,
`jfield2` json NOT NULL
) ;
加载查询:
mysql> load data local infile "/home/user/sample.csv" into table test fields terminated by ',' optionally enclosed by '"' lines terminated by '\n';
ERROR 3140 (22032): Invalid JSON text: "Invalid value." at position 0 in value for column 'test.jfield1'.
mysql>
如果我直接插入数据到表中,插入数据就是正确插入。
mysql> insert into test (id,name,jfield1,jfield2) values (1,"A","{\"Key1\": 100,\"key2\": \"Abc\"}","{}");
Query OK, 1 row affected (0.00 sec)
mysql> insert into test (id,name,jfield1,jfield2) values (1,"B","{\"Key1\": 110,\"key2\": \"Def\"}","{}");
Query OK, 1 row affected (0.00 sec)
mysql> select * from test;
+------+------+------------------------------+---------+
| id | name | jfield1 | jfield2 |
+------+------+------------------------------+---------+
| 1 | A | {"Key1": 100, "key2": "Abc"} | {} |
| 1 | B | {"Key1": 110, "key2": "Def"} | {} |
+------+------+------------------------------+---------+
2 rows in set (0.00 sec)
mysql>
请有人告诉我问题出在哪里。提前谢谢!
3条答案
按热度按时间nzkunb0c1#
试着把你的数据改成这样。使用
\
在逗号之前。lyr7nygr2#
试试这个格式它可以帮助你插入
epfja78i3#
检查你的参数顺序。