一灰灰blog 一灰灰blog
首页
  • InfluxDB
  • MongoDB
  • MySql
  • 基础系列
  • DB系列
  • 搜索系列
  • MQ系列
  • WEB系列
  • 中间件
  • 运维
  • SpringSecurity
  • SpringCloud
  • QuickAlarm
  • QuickCrawer
  • QuickFix
  • QuickMedia
  • QuickSpi
  • QuickTask
  • 高可用
  • 分类
  • 标签
  • 归档
  • 收藏
  • 关于
GitHub (opens new window)

一灰灰blog

资深搬运工
首页
  • InfluxDB
  • MongoDB
  • MySql
  • 基础系列
  • DB系列
  • 搜索系列
  • MQ系列
  • WEB系列
  • 中间件
  • 运维
  • SpringSecurity
  • SpringCloud
  • QuickAlarm
  • QuickCrawer
  • QuickFix
  • QuickMedia
  • QuickSpi
  • QuickTask
  • 高可用
  • 分类
  • 标签
  • 归档
  • 收藏
  • 关于
GitHub (opens new window)
  • InfluxDB

    • v1.6.0安装和简单使用小结
    • InfluxDB基本概念小结
    • 时序数据库InfluxDB之备份和恢复策略
    • InfluxDB之权限管理
    • InfluxDB之配置修改
    • InfluxDb之时间戳显示为日期格式
    • Influx Sql系列教程零:安装及influx-cli使用姿势介绍
    • Influx Sql系列教程一:database 数据库
    • Influx Sql系列教程二:retention policy 保存策略
    • Influx Sql系列教程三:measurement 表
      • II. 其他
        • 0. 系列博文
        • 1. 一灰灰Blog: https://liuyueyi.github.io/hexblog
        • 2. 声明
        • 3. 扫描关注
    • Influx Sql系列教程四:series/point/tag/field
    • Influx Sql系列教程五:insert 添加数据
    • Influx Sql系列教程六:insert 修改数据
    • Influx Sql系列教程七:delete 删除数据
    • Influx Sql系列教程八:query数据查询基本篇
    • Influx Sql系列教程九:query数据查询基本篇二
    • Influx Sql系列教程十:query数据查询基本篇三
  • MongoDB

  • MySql

  • 数据库
  • InfluxDB
一灰灰
2019-07-21

Influx Sql系列教程三:measurement 表

在influxdb中measurement相当于mysql中的表,可以理解为一条一条记录都是存与measurent中的,一个数据库中可以有多个measurement,一个measurement中可以存很多的数据。虽然可将measurement类比为mysql中的表,但是他们之间的差别也挺明显的

首先我们先了解一下measurement的几个常用命令,如何查看、新增删除

# 1. show measurements

查看一个数据库中有哪些measurement,属于常规操作了

  • 先确定数据库
  • 执行show measurements 查看当前数据库的所有measurement
> use test
Using database test
> show measurements
name: measurements
name
----
yhh
1
2
3
4
5
6
7

我们也可以在不执行use databaseName的时候,进行查看;而且还支持按名进行匹配,语法为

SHOW MEASUREMENTS [ON <database_name>] [WITH MEASUREMENT <regular_expression>] [WHERE <tag_key> <operator> ['<tag_value>' | <regular_expression>]] [LIMIT_clause] [OFFSET_clause]
1

下面给出查询指定数据库中,以yhh开头的所有measurement示例

> show measurements on test
name: measurements
name
----
doraemon
doraemon2
yhh
yhh2
> show measurements on test with measurement =~ /yhh*/
name: measurements
name
----
yhh
yhh2
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 2. 创建measurement

在influxdb中没有专门用来创建measurement的命令,在执行向某个measurement新增记录的时候,如果不存在measurement,则会新创建一个

下面是一条简单的演示case

# 像userInfo中新增一条记录,如果userInfo这个measurement不存在,则新建一个
> insert userInfo,name=一灰灰blog userId=10,blog="https://blog.hhui.top/"
> show measurements
name: measurements
name
----
doraemon
doraemon2
userInfo
yhh
yhh2
1
2
3
4
5
6
7
8
9
10
11

# 3. 删除measurement

两种方式,一个是把measurement里面的所有数据都删完,那么这个measurement就没了

> select * from userInfo
name: userInfo
time                blog                   name    userId
----                ----                   ----    ------
1563712849953792293 https://blog.hhui.top/ 一灰灰blog 10
# 删除userInfo中的记录
> delete from userInfo where time=1563712849953792293
# 再次查看,发现userInfo已经被删除
> show measurements
name: measurements
name
----
doraemon
doraemon2
yhh
yhh2
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

另外一种方式就是直接使用drop measurement命令实现删除

# 先创建userInfo
> insert userInfo,name=一灰灰blog userId=10,blog="https://blog.hhui.top/"
> show measurements
name: measurements
name
----
doraemon
doraemon2
userInfo
yhh
yhh2
# 直接使用drop语句删除
> drop measurement userInfo
> show measurements
name: measurements
name
----
doraemon
doraemon2
yhh
yhh2
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 4. 修改

不同于mysql中的表,measurement是没有修改操作的,从前面的创建操作也可以看出,对于measurement而言,也就只有一个名字,那如果我希望重命名现有的measurement,该怎么办?

原则上不建议这么干,如果确实有需要,可以用下面的方式来变相实现

> show measurements
name: measurements
name
----
doraemon
doraemon2
userInfo
yhh
yhh2
# 使用select into语句实现将查询结果保存到另外一个measurement中
> select * into userBaseInfo from userInfo
name: result
time written
---- -------
0    1
> show measurements
name: measurements
name
----
doraemon
doraemon2
userBaseInfo
userInfo
yhh
yhh2
> select * from userBaseInfo, userInfo
name: userBaseInfo
time                blog                   name    name_1 userId
----                ----                   ----    ------ ------
1563713690876924095 https://blog.hhui.top/ 一灰灰blog        10

name: userInfo
time                blog                   name name_1  userId
----                ----                   ---- ------  ------
1563713690876924095 https://blog.hhui.top/      一灰灰blog 10
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

# II. 其他

# 0. 系列博文

  • 190719-Influx Sql系列教程二:retention policy 保存策略 (opens new window)
  • 190717-Influx Sql系列教程零:安装及influx-cli使用姿势介绍 (opens new window)
  • 190509-InfluxDb之时间戳显示为日期格式 (opens new window)
  • 190506-InfluxDB之配置修改 (opens new window)
  • 190505-InfluxDB之权限管理 (opens new window)
  • 180727-时序数据库InfluxDB之备份和恢复策略 (opens new window)
  • 180726-InfluxDB基本概念小结 (opens new window)
  • 180725-InfluxDB-v1.6.0安装和简单使用小结 (opens new window)

参考博文

  • https://docs.influxdata.com/influxdb/v1.7/query_language/schema_exploration/#show-series (opens new window)

# 1. 一灰灰Blog (opens new window): https://liuyueyi.github.io/hexblog

一灰灰的个人博客,记录所有学习和工作中的博文,欢迎大家前去逛逛

# 2. 声明

尽信书则不如,已上内容,纯属一家之言,因个人能力有限,难免有疏漏和错误之处,如发现bug或者有更好的建议,欢迎批评指正,不吝感激

  • 微博地址: 小灰灰Blog (opens new window)
  • QQ: 一灰灰/3302797840

# 3. 扫描关注

一灰灰blog

QrCode

知识星球

goals

编辑 (opens new window)
#InfluxDB#教程
上次更新: 2021/10/15, 19:56:22
Influx Sql系列教程二:retention policy 保存策略
Influx Sql系列教程四:series/point/tag/field

← Influx Sql系列教程二:retention policy 保存策略 Influx Sql系列教程四:series/point/tag/field→

最近更新
01
【基础系列】基于maven多环境配置
04-25
02
【WEB系列】内嵌Tomcat配置Accesslog日志文件生成位置源码探索
04-24
03
【搜索系列】ES查询常用实例演示
04-18
更多文章>
Theme by Vdoing | Copyright © 2017-2022 一灰灰Blog
MIT License | 鄂ICP备18017282号 |
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×