mysql 5.7支持json字段,具体使用方法如下
In version 5.7 you can do something like:
SELECT JSON_EXTRACT(json_field, '$.name');
and it will extract only the name key from json object.
Search all items with the ‘JavaScript’ tag:
SELECT * FROM `table` WHERE JSON_CONTAINS(json_field, '["JavaScript"]');
Find all items with tags starting ‘Java’:
SELECT * FROM `table` WHERE JSON_SEARCH(json_field, 'one', 'Java%') IS NOT NULL;
use ‘one’ to find the first match or ‘all’ to find all matches
You can extract the Twitter nickname using a JSON path:
SELECT name, json_field->"$.twitter" AS `twitter` FROM `user`;
You can also reference a JSON path in the WHERE clause to only return users with a Twitter account:<