Mysql JSON 新特性用法
Mysql 5.7 開始支持 JSON,應用場景有 記錄數據操做日誌, 保留的擴展字段 等等。
- 插入 json 數據
insert into test (json_field) value("{\"col\": val1, \"col2\":\"val2\"...}");
insert into test (json_field) value(json_object(col1,val2, col2, val2)));
- 修改數據
update test set json_field = json_set(json_field, '$.col", val);
- 查詢數據
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;
參照資料
- MySQL 5.7 新增長的 JSON 特性對應的 json 方法
- The JSON Data Type