mysql> select json_extract(`val`, '$.name') as `name`, json_extract(`val`, '$.site') as `site` from `json_table`;
+-----------------+-------------------------+
| name | site |
+-----------------+-------------------------+
| "一灰灰blog" | NULL |
| "一灰灰blog" | "https://blog.hhui.top" |
+-----------------+-------------------------+
接下来再看一下如果为json数组,怎么整
mysql> insert into `json_table` values (3, '[{"name": "一灰灰", "site": "https://spring.hhui.top"}]');
mysql> select json_extract(`val`, '$[0].name') from `json_table` where id = 3;
+----------------------------------+
| json_extract(`val`, '$[0].name') |
+----------------------------------+
| "一灰灰" |
+----------------------------------+
除了在查询结果中使用json_extract之外,也可以在查询条件中使用它
mysql> select * from `json_table` where json_extract(`val`, '$.name') = '一灰灰blog';
+----+------------------------------------------------------------+
| id | val |
+----+------------------------------------------------------------+