mysql json操作 创建表:
CREATE TABLE `t` ( `id` int(11) DEFAULT NULL, `content` json DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
添加
insert into t values(1,{"age":11,"s":"abc"})
修改
update t set content=json_set(content,'$.age','26','$.b','sss') where id=1; 结果 content={"age":26,"s":"abc","b":"bbb"}
删除
update t set content =json_remove(content,'$.b') where id =1; 结果 content={"age":26,"s":"abc"}
查询:
select * from tt WHERE content->'$.age'> 20; #或者 select * from tt where json_extract(content,'$.age') = 24; #或者 select * from tt WHERE content->'$.age' in (23, 24); #或者 select * from tt where content= {"age": 18, "from": "beijin", "name": "php3"};