mysql> CREATE TABLE joson( id INT AUTO_INCREMENT PRIMARY KEY, context JSON NOT NULL)//
Query OK, 0 rows affected (0.05 sec)
mysql> DESC joson;
+---------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| context | json | NO | | NULL | |
+---------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec) mysql> SELECT JSON_ARRAY(1,2,3,4,"AA","BB");
+-------------------------------+
| JSON_ARRAY(1,2,3,4,"AA","BB") |
+-------------------------------+
| [1, 2, 3, 4, "AA", "BB"] |
+-------------------------------+
1 row in set (0.13 sec) mysql> SELECT JSON_OBJECT(1,2,3,4,"AA","BB")
-> ;
+--------------------------------+
| JSON_OBJECT(1,2,3,4,"AA","BB") |
+--------------------------------+
| {"1": 2, "3": 4, "AA": "BB"} |
+--------------------------------+
1 row in set (0.00 sec)
mysql> SET @data = JSON_OBJECT(1,2,3,4,"AA","BB");
Query OK, 0 rows affected (0.00 sec) mysql> SELECT JSON_PRETTY(@data);
+--------------------------------------+
| JSON_PRETTY(@data) |
+--------------------------------------+
| {
"1": 2,
"3": 4,
"AA": "BB"
} |
+--------------------------------------+
1 row in set (0.08 sec) mysql> DESC joson;
+---------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| context | json | NO | | NULL | |
+---------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec) mysql> INSERT INTO joson(context) VALUES(@data);
Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM joson;
+----+------------------------------+
| id | context |
+----+------------------------------+
| 1 | {"1": 2, "3": 4, "AA": "BB"} |
+----+------------------------------+
1 row in set (0.00 sec)
mysql> SET @a = JSON_ARRAY(1,2,3,4);
Query OK, 0 rows affected (0.00 sec) mysql> SELECT @a;
+--------------+
| @a |
+--------------+
| [1, 2, 3, 4] |
+--------------+
1 row in set (0.00 sec) mysql> SELECT JSON_ARRAY_INSERT(@a,"$[0]","quan");
+-------------------------------------+
| JSON_ARRAY_INSERT(@a,"$[0]","quan") |
+-------------------------------------+
| ["quan", 1, 2, 3, 4] |
+-------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_ARRAY_INSERT(@a,"$[3]","zhi");
+------------------------------------+
| JSON_ARRAY_INSERT(@a,"$[3]","zhi") |
+------------------------------------+
| [1, 2, 3, "zhi", 4] |
+------------------------------------+
1 row in set (0.00 sec)
mysql> SET @a = JSON_ARRAY_INSERT(@a,"$[0]","quan");
Query OK, 0 rows affected (0.00 sec) mysql> SELECT @a;
+----------------------+
| @a |
+----------------------+
| ["quan", 1, 2, 3, 4] |
+----------------------+
1 row in set (0.00 sec) mysql> SET @a = JSON_ARRAY_INSERT(@a,"$[3]","zhi");
Query OK, 0 rows affected (0.00 sec) mysql> SELECT @a;
+-----------------------------+
| @a |
+-----------------------------+
| ["quan", 1, 2, "zhi", 3, 4] |
+-----------------------------+
1 row in set (0.00 sec) mysql> SET @b = JSON_OBJECT("id",11,"name","quanzhiqiang");
Query OK, 0 rows affected (0.00 sec) mysql> SELECT @b;
+------------------------------------+
| @b |
+------------------------------------+
| {"id": 11, "name": "quanzhiqiang"} |
+------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT JSON_INSERT(@b,"$.age",90);
+-----------------------------------------------+
| JSON_INSERT(@b,"$.age",90) |
+-----------------------------------------------+
| {"id": 11, "age": 90, "name": "quanzhiqiang"} |
+-----------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT @a;
+-----------------------------+
| @a |
+-----------------------------+
| ["quan", 1, 2, "zhi", 3, 4] |
+-----------------------------+
1 row in set (0.00 sec) mysql> SELECT @b;
+------------------------------------+
| @b |
+------------------------------------+
| {"id": 11, "name": "quanzhiqiang"} |
+------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT JSON_ARRAY_APPEND(@a,"$[0]","111","$[4]","4444");
+--------------------------------------------------+
| JSON_ARRAY_APPEND(@a,"$[0]","111","$[4]","4444") |
+--------------------------------------------------+
| [["quan", "111"], 1, 2, "zhi", [3, "4444"], 4] |
+--------------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_ARRAY_APPEND(@b,"$.name","namename");
+--------------------------------------------------+
| JSON_ARRAY_APPEND(@b,"$.name","namename") |
+--------------------------------------------------+
| {"id": 11, "name": ["quanzhiqiang", "namename"]} |
+--------------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT @b;
+------------------------------------+
| @b |
+------------------------------------+
| {"id": 11, "name": "quanzhiqiang"} |
+------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT JSON_SET(@b,"$.id",90,"$.age",99);
+-----------------------------------------------+
| JSON_SET(@b,"$.id",90,"$.age",99) |
+-----------------------------------------------+
| {"id": 90, "age": 99, "name": "quanzhiqiang"} |
+-----------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT @b;
+------------------------------------+
| @b |
+------------------------------------+
| {"id": 11, "name": "quanzhiqiang"} |
+------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_REPLACE(@b,"$.id",90,"$.age",99);
+---------------------------------------+
| JSON_REPLACE(@b,"$.id",90,"$.age",99) |
+---------------------------------------+
| {"id": 90, "name": "quanzhiqiang"} |
+---------------------------------------+
1 row in set (0.00 sec) mysql> SELECT * FROM joson;
+----+------------------------------+
| id | context |
+----+------------------------------+
| 1 | {"1": 2, "3": 4, "AA": "BB"} |
+----+------------------------------+
1 row in set (0.00 sec) mysql> SELECT context FROM joson
-> ;
+------------------------------+
| context |
+------------------------------+
| {"1": 2, "3": 4, "AA": "BB"} |
+------------------------------+
1 row in set (0.00 sec)
mysql> UPDATE joson SET context = JSON_SET(context,"$.sex",1,"$.homw",2);
Query OK, 1 row affected (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM joson;
+----+---------------------------------------------------+
| id | context |
+----+---------------------------------------------------+
| 1 | {"1": 2, "3": 4, "AA": "BB", "sex": 1, "homw": 2} |
+----+---------------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT @c;
+-----------------------+
| @c |
+-----------------------+
| {"sex": 1, "homw": 2} |
+-----------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_REMOVE(@c,"$.sex");
+-------------------------+
| JSON_REMOVE(@c,"$.sex") |
+-------------------------+
| {"homw": 2} |
+-------------------------+
1 row in set (0.00 sec) mysql> SELECT * FROM joson;
+----+---------------------------------------------------+
| id | context |
+----+---------------------------------------------------+
| 1 | {"1": 2, "3": 4, "AA": "BB", "sex": 1, "homw": 2} |
+----+---------------------------------------------------+
1 row in set (0.00 sec) mysql> UPDATE joson SET context = JSON_REMOVE(context,"$.sex");
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM joson;
+----+-----------------------------------------+
| id | context |
+----+-----------------------------------------+
| 1 | {"1": 2, "3": 4, "AA": "BB", "homw": 2} |
+----+-----------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_EXTRACT(context,"$.homw") FROM joson;
+--------------------------------+
| JSON_EXTRACT(context,"$.homw") |
+--------------------------------+
| 2 |
+--------------------------------+
1 row in set (0.00 sec) mysql> SELECT context->"$.homw" FROM joson;
+-------------------+
| context->"$.homw" |
+-------------------+
| 2 |
+-------------------+
1 row in set (0.00 sec) mysql> SELECT @a;
+-----------------------------+
| @a |
+-----------------------------+
| ["quan", 1, 2, "zhi", 3, 4] |
+-----------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_LENGTH(@a);
+-----------------+
| JSON_LENGTH(@a) |
+-----------------+
| 6 |
+-----------------+
1 row in set (0.00 sec) mysql> SELECT @b;
+------------------------------------+
| @b |
+------------------------------------+
| {"id": 11, "name": "quanzhiqiang"} |
+------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_LENGTH(@b);
+-----------------+
| JSON_LENGTH(@b) |
+-----------------+
| 2 |
+-----------------+
1 row in set (0.00 sec) mysql> SELECT JSON_CONTAINS_PATH(@b,"one","$.id");
+-------------------------------------+
| JSON_CONTAINS_PATH(@b,"one","$.id") |
+-------------------------------------+
| 1 |
+-------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_CONTAINS_PATH(@b,"one","$.idd");
+--------------------------------------+
| JSON_CONTAINS_PATH(@b,"one","$.idd") |
+--------------------------------------+
| 0 |
+--------------------------------------+
1 row in set (0.00 sec) mysql> SELECT JSON_CONTAINS_PATH(@b,"one","$.id","$[11]");
+---------------------------------------------+
| JSON_CONTAINS_PATH(@b,"one","$.id","$[11]") |
+---------------------------------------------+
| 1 |
+---------------------------------------------+
1 row in set (0.00 sec) mysql> SELECT @a;
+-----------------------------+
| @a |
+-----------------------------+
| ["quan", 1, 2, "zhi", 3, 4] |
+-----------------------------+
1 row in set (0.00 sec)
mysql> SELECT JSON_CONTAINS(@a,"1","$[1]");
+------------------------------+
| JSON_CONTAINS(@a,"1","$[1]") |
+------------------------------+
| 1 |
+------------------------------+
1 row in set (0.00 sec) mysql> SELECT @a;
+-----------------------------+
| @a |
+-----------------------------+
| ["quan", 1, 2, "zhi", 3, 4] |
+-----------------------------+
1 row in set (0.00 sec)
mysql> SELECT JSON_CONTAINS(@a,"1");
+-----------------------+
| JSON_CONTAINS(@a,"1") |
+-----------------------+
| 1 |
+-----------------------+
1 row in set (0.00 sec)
mysql> SELECT JSON_CONTAINS(@a,"3");
+-----------------------+
| JSON_CONTAINS(@a,"3") |
+-----------------------+
| 1 |
+-----------------------+
1 row in set (0.00 sec)

MYSQL5.8----M4-5的更多相关文章

  1. Red Hat5.5 install Generic mysql-5.7.10

    1.确认以下依赖包已安装 [ncurses ncurses-devel openssl-devel bison autoconf automake bison gcc m4 libtool make ...

  2. Red Hat5下源码安装mysql5.6过程记录

    1.安装cmake包 [root@edu soft]# tar -xzf cmake-.tar.Z [root@edu soft]# cd cmake- [root@edu cmake-]# ./co ...

  3. 年终福利,PHP7+Apache2.4+MySQL5.6 源码编译安装,环境配置,搭建你自己的LAMP环境

    PHP7 都出来了,你还在玩PHP5吗? MySQL5.6 早都出来了,你还在玩MySql5.2吗? Apache2.4 早都出来了,你还在玩Apache2.2吗? 笔者不才,愿意亲自搭建环境,供搭建 ...

  4. Centos6.7安装Apache2.4+Mysql5.6+Apache2.4

    首先说下思路,因为一开始系统上已经跑了一套完成的 PHP 环境,那时候都是快速自动安装的,如果是跑一些5.3以下版本的话,很简单,几个指令,10分钟搞定了. 但现在要升级,彻底一点的话,唯有推倒重来了 ...

  5. [Ubuntu] Ubuntu14.04 64bit 编译安装nginx1.7+php5.4+mysql5.6

    我的操作系统是Ubuntu14.04,其它linux系统的操作流程类似. 主要安装的软件是nginx1.7+php5.4+mysql5.6 1. 创建必要目录 sudo mkdir ~/setup s ...

  6. CentOS6.6系统源代码安装mysql5.5.28教程(附源码包下载地址)+sysbench的安装

    mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档(※ 非常重要) http://dev.mysql.com/ ...

  7. centos下编译安装mysql5.6

    CentOS 6.4下编译安装MySQL 5.6.14 参考:http://www.cnblogs.com/xiongpq/p/3384681.html 概述: CentOS 6.4下通过yum安装的 ...

  8. centos6.7编译安装mysql5.7.17

    centos6.7编译安装mysql5.7.17 2017-03-24 09:57:15 提示:mysql5.7.17和之前5.56以前的版本安装不一样,需要用cmake 另外,看本文档的mysql编 ...

  9. CentOS 7.2mini版本下编译安装php7.0.10+MySQL5.7.14+Nginx1.10

    一.安装前的准备工作 1.yum update    #更新系统 2.yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2  ...

  10. mysql5.7-Group Replication

    什么是Group Replication 基于组的复制(Group-based Replication)是一种被使用在容错系统中的技术.Replication-group(复制组)是由能够相互通信的多 ...

随机推荐

  1. 安装多个版本的MySQL

    安装多个版本的MySQL 之前在PC机上安装了 MySQL 5.5 后续发现了窗口函数,而窗口函数是 MySQL8 以后才支持的,故在本地又安装了一个 MySQL 8 安装MySQL 5.5 进入my ...

  2. 2021.7.15考试总结[NOIP模拟16]

    ZJ模拟D2就是NB.. T1 Star Way To Heaven 谁能想到这竟是个最小生成树呢?(T1挂分100的高人JYF就在我身边 把上边界和下边界看成一个点和星星跑最小生成树,从上边界开始跑 ...

  3. stm32直流电机驱动与测速学习总结

    通过实验发现,定时器的一个通道控制一个pwm信号. 在正式开始之前也可以参考这个视频学习资料 (stm32直流电机驱动) http://www.makeru.com.cn/live/1392_1218 ...

  4. [LGP1866]编号

    传送门 题意:找n个数,使得 $ 1 \leq a_i \leq Maxnumber_i $ 求有多少种组合 这题我们可以看到,还有一种无解的情况 我们可以先判断无解的情况 首先把Maxnumber数 ...

  5. webshell绕过D盾

    PHP常见的代码执行函数: eval() assert() preg_replace() create_function() array_map() call_user_func() call_use ...

  6. Java设计模式——模板设计模式

    模板设计模式 1.模板模式简介 模板模式(Template ):模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑 ...

  7. 『学了就忘』Linux基础 — 13、Linux系统的分区和格式化

    目录 1.Linux系统的分区 (1)磁盘分区定义 (2)两种分区表形式 (3)MBR分区类型 2.Linux系统的格式化 (1)格式化定义 (2)格式化说明 1.Linux系统的分区 (1)磁盘分区 ...

  8. Spring---IoC(控制反转)原理学习笔记【全】

    1.IoC创建对象的方式 使用无参构造创建对象 假如要使用有参构造创建: 下标赋值constructor-arg <!--有参--> <bean id="User" ...

  9. Spring Cloud Alibaba 使用Nacos作为配置管理中心

    为什么需要配置中心? 动态配置管理是 Nacos 的三大功能之一,通过动态配置服务,我们可以在所有环境中以集中和动态的方式管理所有应用程序或服务的配置信息. 动态配置中心可以实现配置更新时无需重新部署 ...

  10. linked-list-cycle-ii leetcode C++

    Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull. Follo ...