InfluxDB之基本概念和操作(第二节)-yellowcong

使用influxdb得时候,需要说明一下,每条sql 执行语句,不需要加上分毫来说明这个是结尾,由于之前mysql得经验,都会习惯上加上 分号, 在创建表和插入数据得时候,加上分号,会产生错误得问题。

influxdb 和Mysql概念对比

字段 influxdb mysql
数据库 database database
表名称 measurements table
索引 tag index

1. 登陆数据库

#登陆数据库
#-precision rfc3339   rfc3339时间格式 'YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ'
influx -precision rfc3339
#登陆数据库,并指定哪个库
influx -precision rfc3339 -database NOAA_water_database

在这里插入图片描述

2 数据库管理

# 查看数据库
show databases;

#创建数据库
create database yellowcong ;

#删除数据库
drop database yellowcong;

#使用库
use yellowcong 

在这里插入图片描述

3 表操作

influxdb中,没有显式的新建表的语句,只能通过insert数据的方式来建立新表。 第一个插入得数据,确定了表得格式,第二条就必须按照第一条得规则进行数据库得插入操作

#使用yellowcong 这个数据库
use yellowcong

#查看表,这个同mysql得有所区别
show measurements 

#新建表
#InfluxDB中没有显式的新建表的语句,只能通过insert数据的方式来建立新表。
#disk_free 是表名称
#hostname=server01 这个是tag (注意点,tag是支持查询得,field 是不支持查询得)
#value=442221834240 这个是field ,记录值可以是多个
#注意得地方,在influxdb中,不需要加上分号(;) 来结尾
insert disk_free,hostname=server01 value=442221834240

#删除表
drop measurement  disk_free;


#查询当前一小时前得数据
select * from h2o_feet_2index where time > now() -1h 

在这里插入图片描述

3.1 多个value得情况

#通过\  解决key 值,分开得问题
insert h2o_feet,location=coyote_creek water_level=2.907,level\ description="below 3 feet" 1440721440
insert h2o_feet,location=coyote_creek water_level=2.841,level\ description="below 3 feet" 1440721800
insert h2o_feet,location=coyote_creek water_level=2.769,level\ description="below 3 feet" 1440722160
insert h2o_feet,location=coyote_creek water_level=2.700,level\ description="below 3 feet" 1440722520

#

在这里插入图片描述

3.2 多个索引得情况

#两个索引
insert h2o_feet_2index,location=coyote_creek,day=12 water_level=2.700,level\ description="below 3 feet" 
insert h2o_feet_1index,location=coyote_creek,day=12 water_level=2.700,level\ description="below 3 feet" 


SHOW MEASUREMENTS
#查看索引
show tag keys from "h2o_feet_2index"

#查看索引得值
show tag values from "h2o_feet_2index" with key = "location"

可以看到,现在得服务可以看到索引信息有两个。
在这里插入图片描述

4 数据库策略

InfluxDB是一个实时得数据库,所以必然就会有存储时间得限定了,不然一直得存储数据,就会导致磁盘爆炸。

## 数据库保存策略
#yellowcong 数数据库得名称
#可以看到默认给了 168 h 得保留时间,也就是7天得时间
show retention policies on "yellowcong" ;

#
#3w (w 信息,d 天,h 小时)
#default 设置这个过期策略为默认得策略
#rp_yellowcong 策略名称
#yellowcong 库名称
create retention policy "rp_yellowcong" on "yellowcong" duration 3w replication 1 default


#删除策略
drop retention policy "rp_yellowcong" on "yellowcong" 


在这里插入图片描述

设定保存策略
在这里插入图片描述

5 用户管理

5.1 开启授权验证

修改配置文件,/etc/influxdb/influxdb.conf ,在http节点里面,开启授权验证

#配置需要添加授权
auth-enabled = true

在这里插入图片描述

5.2 配置用户

#显示用户
show users
 
#创建用户
create user "username" with password 'password'
 
#创建管理员权限用户
create user "username" with password 'password' with all privileges
create user "yellowcong" with password 'yellowcong' with all privileges
 
#删除用户
drop user "username"

#授权
GRANT READ ON [database] to "user"
GRANT WRITE ON [database] to "user"

#密码登陆influx服务
influx -username admin -password ''

参考文章

https://www.cnblogs.com/shhnwangjian/p/6897216.html?utm_source=itdadao&utm_medium=referral
https://www.jianshu.com/p/a1344ca86e9b
https://www.cnblogs.com/wzbk/p/10569683.html
https://blog.csdn.net/vtnews/article/details/80197045
https://blog.csdn.net/u010185262/article/details/53158786
https://www.cnblogs.com/gaoguangjun/p/8513054.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章