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

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