mongodb在文档型数据库这方面一直做的很好,也发展了很多年,MySQL作为一个比较大众的数据库也慢慢支持了该特性,下面介绍一下MySQL支持文档型数据库的简单操作。

环境:

主机名 IP 系统 软件
master 192.168.91.46 RHEL MYSQL8.0.17/mysqlsh   Ver 8.0.17

[root@master ~]# mysqlsh --mysqlx  -u root  -pkavl7kAkkle! --file /opt/world_x-db/world_x.sql WARNING: Using a password on the command line interface can be insecure.  建立schema

Records: 4079  Duplicates: 0  Warnings: 0

Records: 239  Duplicates: 0  Warnings: 0

Records: 239  Duplicates: 0  Warnings: 0

Records: 984  Duplicates: 0  Warnings: 0

进入库中:

[root@master ~]# mysqlsh --mysqlx  -u root  -pkavl7kAkkle! --database world_x

MySQL Shell 8.0.17

Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates.

Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.

WARNING: Using a password on the command line interface can be insecure.

Creating an X protocol session to 'root@localhost/world_x' Fetching schema names for autocompletion... Press ^C to stop.

Your MySQL connection id is 240126 (X protocol)

Server version: 8.0.17 MySQL Community Server - GPL

Default schema `world_x` accessible through db.

MySQL  localhost:33060+ ssl  world_x  JS >

或者:

[root@master ~]# mysqlsh --mysqlx  -u root  -pkavl7kAkkle!

MySQL  localhost:33060+ ssl  JS > \use world_x
Default schema `world_x` accessible through db.
 MySQL  localhost:33060+ ssl  world_x  JS >

获取所有的表

MySQL  localhost:33060+ ssl  world_x  JS > db.getCollections()
[
    <Collection:countryinfo>
]

查看所有的数据:

MySQL  localhost:33060+ ssl  world_x  JS > db.countryinfo.find().limit(1)
{
    "GNP": 828,
    "_id": "ABW",
    "Name": "Aruba",
    "IndepYear": null,
    "geography": {
        "Region": "Caribbean",
        "Continent": "North America",
        "SurfaceArea": 193
    },
    "government": {
        "HeadOfState": "Beatrix",
        "GovernmentForm": "Nonmetropolitan Territory of The Netherlands"
    },
    "demographics": {
        "Population": 103000,
        "LifeExpectancy": 78.4000015258789
    }
}
1 document in set (0.0005 sec)
 MySQL  localhost:33060+ ssl  world_x  JS >

统计有多少条数据:

MySQL  localhost:33060+ ssl  world_x  JS > db.countryinfo.count()
239

创建一个表:

MySQL  localhost:33060+ ssl  world_x  JS > db.createCollection("student_info");
<Collection:student_info>

MySQL  localhost:33060+ ssl  world_x  JS > db.getCollections()
[
    <Collection:countryinfo>,
    <Collection:student_info>
]

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.add({name:'thunder',age:27,gender:"man"})
Query OK, 1 item affected (0.0066 sec)

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.add({aihao:"pingpang",yuyan:"shell"})
Query OK, 1 item affected (0.0076 sec)

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.add({name:'ss',age:25,gender:"girl"})
Query OK, 1 item affected (0.0072 sec)
 MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.add({name:'aa',age:24,gender:"girl"})
Query OK, 1 item affected (0.0039 sec)
 MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.add({name:'jj',age:27,gender:"boy"})
Query OK, 1 item affected (0.0118 sec)

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.find()
{
    "_id": "00005da579b70000000000000001",
    "age": 27,
    "name": "thunder",
    "gender": "man"
}
{
    "_id": "00005da579b70000000000000002",
    "aihao": "pingpang",
    "yuyan": "shell"
}
2 documents in set (0.0005 sec)

按照条件查询

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.find("age=27")
{
    "_id": "00005da579b70000000000000001",
    "age": 27,
    "name": "thunder",
    "gender": "man"
}
1 document in set (0.0008 sec)

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.find("age>27")
Empty set (0.0007 sec)

删除文档的语法结构:

db.集合名称.remove(条件)
MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.find("age=24")
{
    "_id": "00005da579b70000000000000004",
    "age": 24,
    "name": "qian",
    "gender": "girl"
}
{
    "_id": "00005da579b70000000000000008",
    "age": 24,
    "name": "aa",
    "gender": "girl"
}
2 documents in set (0.0006 sec)

MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.remove("age=24")
Query OK, 2 items affected (0.0044 sec)
 MySQL  localhost:33060+ ssl  world_x  JS > db.student_info.find("age=24")
Empty set (0.0004 sec)

MySQL新特性文档型数据库的更多相关文章

  1. MongoDB,无模式文档型数据库简介

    MongoDB的名字源自一个形容词humongous(巨大无比的),在向上扩展和快速处理大数据量方面,它会损失一些精度,在旧金山举行的MondoDB大会上,Merriman说:“你不适宜用它来处理复杂 ...

  2. MongoDB系列一:MongoDB文档型数据库特点介绍

    一.MongoDB数据库的存储特点: 1.MongoDB是文档型数据库,存储的是文档(将json二进制化为Bson存储): 2.存储的每篇文档都可以有自己独特的存储结构,颠覆了传统数据库必须按照表和列 ...

  3. MongoDB小型文档型数据库使用

    MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中 ...

  4. Proftpd mysql认证配置文档

    Proftpd mysql认证配置文档 ver1.0, 2012/09/25 一.下载安装proftp mysql 下载 wget http://cloud.github.com/downloads/ ...

  5. 不想业务被中断?快来解锁华为云RDS for MySQL新特性

    摘要:新特性上线!华为云RDS for MySQL又添新技能,实力保障业务连续性. 本文分享自华为云社区<不想业务被中断?快来解锁华为云RDS for MySQL新特性>,作者:Gauss ...

  6. 在Delphi中处理word文档与数据库的互联 1

    在Delphi中处理word文档与数据库的互联 ---- 目前,Delphi被越来越多的人选中作为MIS系统开发中的前台工具.在以Delphi为前台,一些大型数据库为后台的MIS系统中,图形的处理不可 ...

  7. 在Delphi中处理word文档与数据库的互联

    在Delphi中处理word文档与数据库的互联 ---- 目前,Delphi被越来越多的人选中作为MIS系统开发中的前台工具.在以Delphi为前台,一些大型数据库为后台的MIS系统中,图形的处理不可 ...

  8. Elasticsearch-更新现有文档

    ES-更新现有文档 ES的更新API允许发送文档所需要做的修改,而且API会返回一个答复,告知操作是否成功.更新流程如下 1. 检索现有的文档.为了使这步奏效,必须打开_source字段,否则ES并不 ...

  9. NPOI word文档表格在新的文档中多次使用

    最近有一个项目,涉及到文档操作,有一个固定的模版,模版中有文字和表格,表格会在新的文档中使用n多次 //获取模版中的表格FileStream stream = new FileStream(strPa ...

随机推荐

  1. (七)freemarker的基本语法及入门基础

    一.freemarker模板文件(*.ftl)的基本组成部分 1. 文本:直接输出的内容部分        2. 注释:不会输出的内容,格式为<#--  注释内容  -->         ...

  2. 在论坛中出现的比较难的sql问题:3(row_number函数 分组查询)

    原文:在论坛中出现的比较难的sql问题:3(row_number函数 分组查询) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所 ...

  3. XXX银行人事管理系统-数据库设计

    1. 用户.权限.角色关系用户基本信息 userinfo [人员表]权限表actions[权限表]员工类型表usertype [管理组表]权限映射表actionmapping [权限映射表]权限分栏表 ...

  4. stm32 usart 串口

    比特率是每秒钟传输二进制代码的位数,单位是:位/秒(bps).如每秒钟传送240个字符, 而每个字符格式包含10位(1个起始位.1个停止位.8个数据位),这时的比特率为: 10位 × 240个/秒 = ...

  5. bootstrap 分页行数选择按钮失效

    原因是bootstrap.js重复加载,button点击作用两次,导致没效果

  6. BeginInvoke异步线程

    this.BeginInvoke(new Action(() => { dataGridView1.DataSource = BLLBillConsume.BllGetClearMarketLo ...

  7. IDEA部署项目到远程服务器

    一.idea安装阿里插件Alibaba Cloud Toolkit 二.添加Host 三.应用部署 四.修改源程序重新部署 五.查看实时日志 欲买桂花同载酒,终不似,少年游

  8. c#创建目录和文件夹,数据写入并生成txt文件

    c#创建目录: // 获取程序的基目录.System.AppDomain.CurrentDomain.BaseDirectory // 获取模块的完整路径.System.Diagnostics.Pro ...

  9. 堆(heap)和栈(stack)、内存泄漏(memory leak)和内存溢出

    来源:http://blog.itpub.net/8797129/viewspace-693648/ 简单的可以理解为:heap:是由malloc之类函数分配的空间所在地.地址是由低向高增长的.sta ...

  10. 用arduino的uno开发板为nano板子烧写bootloader

    这篇文章,是为了记录下某宝上淘到的一个没有bootloader的nano开发板的历程(比较坑),自己搜索资料而记录的. 如果没有bootloader,板子就不能接收上传的程序,什么也干不了. 烧写bo ...