Mysql JSON 新特性用法

Mysql JSON 新特性用法

Mysql 5.7 开始支持 JSON,应用场景有 记录数据操做日志, 保留的扩展字段 等等。

  1. 插入 json 数据
insert into test (json_field) value("{\"col\": val1, \"col2\":\"val2\"...}");
insert into test (json_field) value(json_object(col1,val2, col2, val2)));
  1. 修改数据
update test set json_field = json_set(json_field, '$.col", val);
  1. 查询数据
select json_extract(json_field, "$.col") from test;

select JSON_UNQUOTE(json_extract(json_field, "$.col")) from test;

select json_field -> "$.col"from test;

select json_field ->> "$.col" from test;

参照资料

  1. MySQL 5.7 新增长的 JSON 特性对应的 json 方法
  2. The JSON Data Type
相关文章
相关标签/搜索