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)
相關文章
相關標籤/搜索