In this Pique, you will learn how to set up multiple InfluxDB connections using the influx config command from influxdb-client.
I know you want to do some queries, create users or make any change to your InfluxDB instance from the CLI, and it may be is not cool to enter the organization name, the URL of the instance, and the token every time your want to do something.
Before this post (😅), for example, to create a user in an instance of InfluxDB, you need to run the following:
$ ./influx user create -n username -p password --host http://localhost:8086 -o my-org -t $INFLUX_TOKEN
But, now, you can run this one...
$ ./influx create user -n user-name - password
Influxdb-client can manage configs; these save your InfluxDB instance's data to make it more comfortable to run queries and make configurations without the need to specify all the data related to your instance every time.
First, you need to download the CLI:
$ wget https://dl.influxdata.com/influxdb/releases/influxdb_client_2.0.2_linux_amd64.tar.gz
uncompress and enter to the folder:
$ tar xvfz influxdb_client_2.0.2_linux_amd64.tar.gz && cd influxdb_client_2.0.2_linux_amd64
To create a config, you need to run the following:
$ ./influx config create --active \ -n my-awesome-config \ -u http://localhost:8086 \ -t my-awesome-token \ -o my-awesome-org
In this case, I'm setting that the config that I just created is active, but if you don't want that config is active, run the same without --active:
./influx config create \ -n my-awesome-config \ -u http://localhost:8086 \ -t my-awesome-token \ -o my-awesome-org
To get more information about how the configs works, refer to this doc in InfluxData Website:
Easy peasy lemon squeezy