我有一个包含2列的MySQL(版本5.7.21)数据库:
id
是一个简单的自动增量字段INT(11)
和jsondata
是一个JSON对象字段。
我需要导入的JSON如下所示:
{
"archive": "0iHBvqAX-2017-12-10T23:15:06",
"barchive": "0iHBvqAX-2017-12-10T23:15:06",
"id": "698fd4fd641a211fb569f704ee114f9829505a567ebc85502ea030705038600b",
"name": "0iHBvqAX-2017-12-10T23:15:06",
"start": "2017-12-10T23:15:08.000000",
"time": "2017-12-10T23:15:08.000000"
}
这是我的MySQL导入:
LOAD DATA LOCAL INFILE 'myfile.json' INTO TABLE thetable(jsondata);
错误:
ERROR 3140 (22032): Invalid JSON text: "Missing a name for object member." at position 1 in value for column 'thetable.jsondata'.
现在,如果我们删除所有这样的返回:
{ "archive": "0iHBvqAX-2017-12-10T23:15:06", "barchive": "0iHBvqAX-2017-12-10T23:15:06", "id": "698fd4fd641a211fb569f704ee114f9829505a567ebc85502ea030705038600b", "name": "0iHBvqAX-2017-12-10T23:15:06", "start": "2017-12-10T23:15:08.000000", "time": "2017-12-10T23:15:08.000000" }
导入工作完美。有没有办法告诉MySQL忽略JSON文件中的\n
?