update m_imports set properties = json_replace(properties, '$.defaults.tags',json_array('153','154'))
创建表
CREATE
TABLE
t_json(id
INT
PRIMARY
KEY
,
NAME
VARCHAR
(20) , info JSON);
插入记录
INSERT
INTO
t_json(id,sname,info)
VALUES
(1 ,
'test'
,
'{"time":"2017-01-01 13:00:00","ip":"192.168.1.1","result":"fail"}'
);
INSERT
INTO
t_json(id,sname,info)
VALUES
(2 ,
'my'
,JSON_OBJECT(
"time"
,NOW(),
'ip'
,
'192.168.1.1'
,
'result'
,
'fail'
));
查询IP键
SELECT
sname,JSON_EXTRACT(info,
'$.ip'
)
FROM
t_json;
查询有多少个键
SELECT
id,json_keys(info)
AS
"keys"
FROM
t_json;
删除键
UPDATE
t_json
SET
info = json_remove(info,
'$.ip'
);
增加键
UPDATE
t_json
SET
info = json_set(info,
'$.ip'
,
'192.168.1.1'
);
变更值
UPDATE
t_json
SET
info = json_set(info,
'$.ip'
,
'192.168.1.2'
);