Golang influxdb basic operation


Infixdb basic operation

Basic operation

  • connect

    [[email protected] ~]#  influx -precision rfc3339
    Connected to http://localhost:8086 version 1.8.0
    InfluxDB shell version: 1.8.0

    precisionThe parameter indicates the format and precision of any returned timestamp. In the above example,rfc3339Yes, let influxdb returnRFC339Timestamp of format (yyyy-mm-ddthh: mm: SS. Nnnnnnnz).

  • validate logon

    > auth
    username: icms
    password: [email protected]
  • Operation database

    #Create user
    create user "icms" with password '[email protected]' with all privileges
    #Create database and retention policy RPS
    #When the policy name is "with policy # 2 days", it means "with policy # 2 days"
    #The replica slice parameter (replication 1) is required, but for an influxdb instance of a single node, the replica slice can only be set to 1
    #Name "cache_policy_2d" the name of the retention policy
    SHARD DURATION 1h NAME "cache_policy_2d"

    WITHDURATIONREPLICATIONSHARD DURATIONandNAMEClause is optional to create a single retention policy associated with the database. If you are not inWITHThen specify one of the clauses, which will default toautogenRetention policy. The retention policy created is automatically used as the default retention policy for the database.

    A successfulCREATE DATABASEThe query returns an empty result. If you try to create an existing database, influxdb does nothing and returns no errors.

    #Show all databases
    > show databases
    name: databases
    #Show retention policy
    show retention policies on "db_name"
    #Use specified database
    > use ICMS_CACHE
    Using database ICMS_CACHE
    #Display all tables (similar to MySQL table)
    > show measurements
    name: measurements
    #Show tags field
    > show tag keys on ICMS_CACHE from DevPropData
    name: DevPropData
    #Display field
    >  show field keys on ICMS_CACHE from DevPropData
    name: DevPropData
    fieldKey fieldType
    -------- ---------
    Alarm    integer
    AreaId   integer
    DevId    integer
    FloorNo  integer
    Interval integer
    N1       float

    explain:_internalThe database is used to store the real-time monitoring data inside the influxdb.

  • Addition, deletion, modification and query (Cu RD)

    #Operation database
    >  use ICMS_CACHE
    Using database ICMS_CACHE
    #It is recommended to set the console time display format before querying data
    > precision rfc3339
    #Time zone setting TZ ('asia / Shanghai ') needs to be added to query TOP10 data by time, otherwise the queried data is inaccurate
    > select * from DevPropData order by time desc limit 10 tz('Asia/Shanghai')
    name: DevPropData
    time                                Alarm   DevId DevName FloorNo Interval
    ----                                -----   ----- ------- ------- --------
    2020-07-22T10:52:00.000359379+08:00 1       1     403A    4       30      
    2020-07-22T10:51:30.000251776+08:00 1       1     403A    4       30      
    2020-07-22T10:51:00.000522171+08:00 1       1     403A    4       30      
    2020-07-22T10:50:30.000343237+08:00 1       1     403A    4       30      
    2020-07-22T10:50:00.000213782+08:00 1       1     403A    4       30      
    2020-07-22T10:49:30.000360242+08:00 1       1     403A    4       30      
    2020-07-22T10:49:00.000293949+08:00 1       1     403A    4       30      
    2020-07-22T10:48:30.000312107+08:00 1       1     403A    4       30      
    2020-07-22T10:48:00.00023421+08:00  1       1     403A    4       30      
    2020-07-22T10:47:30.000334161+08:00 1       1     403A    4       30      
    #Query by fields field. Fields needs double quotation marks
    > select * from DevPropData where "DevId"=1 limit 1
    name: DevPropData
    time                         Alarm AreaId AreaName DevId DevName FloorNo Interval 
    ----                         ----- ------ -------- ----- ------- ------- -------- 
    2020-07-21t14:36:30.0008914z 1 5 Building B 1 403a 4 30       
    #Query the specified indicators by fields
    > SELECT "DevId" , "AreaId", "AreaName" FROM DevPropData where "DevId"=1 limit 1
    name: DevPropData
    time                         DevId AreaId AreaName
    ----                         ----- ------ --------
    2020-07-21t14:36:30.0008914z 1 5 Building B
    #Add data

Recommended Today

[Android] understand why dialog cannot be displayed in the application from the perspective of source code

First, write a demo: image.png After running, the following errors will be reported: image.png How did this mistake come about, the so-calledtoken null is not validWhat is the token in? In this article, we will analyze the source code. 1. Error tracking First, follow the steps of the source code to track why this error […]