首页 >> 大全

mysql5.7原生json_MySQL数据库之10分钟了解MySQL5

2023-12-23 大全 28 作者:考证青年

本文主要向大家介绍了MySQL数据库之10分钟了解.7对原生JSON的支持与用法 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。

Part1:JSON格式的支持

.7版本终于支持了原生的JSON格式,即将关系型数据库和文档型数据库集于一身。本文接下来将对这特性分别就.7和.1各自实现的方法异同进行介绍和演示

_数据库json_json数据源

Part2:创建相应表结构

[root@HE3 ~]# mysql -V

mysql Ver 14.14 5.7.15, for linux-.5 () using

_json数据源_数据库json

mysql> helei;Query OK, 1 row (0.00 sec)mysql> use helei; > table helei (id int(10) NOT NULL, json null, key(id));Query OK, 0 rows (0.02 sec)mysql> show table helei \G*************************** 1. row *************************** Table: Table: TABLE `helei` ( `id` int(10) NOT NULL, `` json NULL, KEY (`id`)) = =utf81 row in set (0.02 sec)

Part3:构造数据&测试

mysql> desc helei;+---------+------------------+------+-----+---------+-------+| Field | Type | Null | Key | | Extra |+---------+------------------+------+-----+---------+-------+| id | int(10) | NO | PRI | NULL | || | json | YES | | NULL | |+---------+------------------+------+-----+---------+-------+2 rows in set (0。00 sec)mysql> into helei (1,'{"name":"贺磊","age":100}'),(2,'{"name":"陈加持","age":30}'),(3,'{"name":"于浩","age":28}');Query OK, 3 rows (0。

00 sec): 3 : 0 : > * from helei;+----+----------------------------------+| id | |+----+----------------------------------+| 1 | {"age": 100, "name": "贺磊"} || 2 | {"age": 30, "name": "陈加持"} || 3 | {"age": 28, "name": "于浩"} |+----+----------------------------------+3 rows in set (0。00 sec)mysql> id,(,'$。name') name,(,'$。age') age from helei;+----+-------------+------+| id | name | age |+----+-------------+------+| 1 | "贺磊" | 100 || 2 | "陈加持" | 30 || 3 | "于浩" | 28 |+----+-------------+------+3 rows in set (0。

00 sec)获取Key-> id,() from helei;+----+--------------------+| id | () |+----+--------------------+| 1 | ["age", "name"] || 2 | ["age", "name"] || 3 | ["age", "name"] |+----+--------------------+3 rows in set (0。00 sec)获取全部> helei set =(,'$。name',"贺磊",'$。','')where id=1;Query OK, 1 row (0。00 sec)Rows : 1 : 1 : > * from helei;+----+------------------------------------------------------+| id | |+----+------------------------------------------------------+| 1 | {"age": 100, "name": "贺磊", "": ""} || 2 | {"age": 30, "name": "陈加持"} || 3 | {"age": 28, "name": "于浩"} |+----+------------------------------------------------------+3 rows in set (0。

00 sec)增加Key-> helei set =(,'$。name',"高穷帅")where id=1;Query OK, 1 row (0。01 sec)Rows : 1 : 1 : > * from helei;+----+---------------------------------------------------------+| id | |+----+---------------------------------------------------------+| 1 | {"age": 100, "name": "高穷帅", "": ""} || 2 | {"age": 30, "name": "陈加持"} || 3 | {"age": 28, "name": "于浩"} |+----+---------------------------------------------------------+3 rows in set (0。

00 sec)变更key-> helei set =(,'$。name') where id=1;Query OK, 1 row (0。01 sec)Rows : 1 : 1 : > * from helei;+----+------------------------------------+| id | |+----+------------------------------------+| 1 | {"age": 100, "": ""} || 2 | {"age": 30, "name": "陈加持"} || 3 | {"age": 28, "name": "于浩"} |+----+------------------------------------+3 rows in set (0。00 sec)删除Key-Value

本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了