Mysql5.7支持Json数据类型

MySQL 5.7 使用原生JSON类型的例子mysql

1、建立表sql

CREATE TABLE `json` (
  `id` int(11) DEFAULT NULL,
  `content` json DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2、插入数据json

mysql> insert into json values(3,'{"name":"测试"}');
Query OK, 1 row affected (0.06 sec)

3、查询数据测试

mysql> select * from json;
+------+---------------------+
| id   | content             |
+------+---------------------+
|    1 | {"title": "标题"}   |
|    2 | {"title": "新闻"}   |
|    3 | {"name": "测试"}    |
+------+---------------------+
3 rows in set (0.00 sec)

mysql> select * from json where content->'$.title' = '标题';
+------+---------------------+
| id   | content             |
+------+---------------------+
|    1 | {"title": "标题"}   |
+------+---------------------+
1 row in set (0.00 sec)

mysql> select * from json where content->'$.title' like '%新%';
+------+---------------------+
| id   | content             |
+------+---------------------+
|    2 | {"title": "新闻"}   |
+------+---------------------+
1 row in set (0.00 sec)
相关文章
相关标签/搜索