Open ryanwalexander opened 4 years ago
OK. I think the short answer is that you are not doing anything wrong. I don't think the INFLUXDB_DB
key works. I think its presence in the IOTstack environment template for InfluxDB is an error.
I say this because:
INFLUXDB_DB
anywhere in the current documentation;A restricted Google search for that exact key results in:
Your search - "INFLUXDB_DB" site:docs.influxdata.com - did not match any documents.
so it doesn't look to me like any part of the InfluxDB docs ever knew about that exact key; and
From what you wrote, it sounds like you are talking about the first use-case (expecting that INFLUXDB_DB will create the database "mydb" automatically). I don't have all that much experience with InfluxDB but I haven't found a way of doing that.
I have played with quite a few SQL databases over the years and, while I might be mis-remembering (rose-coloured glasses and all that), I can't actually think of one where you did not at least have to create each database by hand, and usually the table schema too. Sure, there might be an API between you and the database engine that takes care of details like that but not if you are talking direct to the CLI for the database.
I have these aliases defined and I will use them in the examples:
alias INFLUX_RESTART='pushd ~/IOTstack;docker-compose up -d; popd'
alias INFLUX_SERVICES='cd ~/IOTstack/services/influxdb; ls'
alias INFLUX_SHELL='docker exec -it influxdb bash'
alias influx='docker exec -it influxdb influx -precision=rfc3339'
To create "mydb" I would go into the InfluxDB CLI:
$ influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
>
First, demonstrate that "mydb" does not exist:
> use mydb
ERR: Database mydb doesn't exist. Run SHOW DATABASES for a list of existing databases.
DB does not exist!
> show databases
name: databases
name
----
power
weather
airquality
_internal
Then, create the database:
> create database mydb
> show databases
name: databases
name
----
power
weather
airquality
_internal
mydb
> exit
$
Now, what about selecting a database by default. Does INFLUXDB_DB do that? Let's give that a whirl:
$ INFLUX_SERVICES
$ vi influxdb.env
# added "INFLUXDB_DB=power" as the first line
$ head -1 influxdb.env
INFLUXDB_DB=power
$ INFLUX_RESTART
Recreating influxdb ... done
Prove that the container environment knows about the change:
$ INFLUX_SHELL
# set | grep INFLUXDB_DB
INFLUXDB_DB=power
# exit
$
Does that result in "power" being selected as the default database?
$ influx
> show series
ERR: database name required
> exit
$
Answer = no.
Is it possible to have a database selected by default when I go into the Influx CLI? Yes, by passing an argument to the command:
$ influx -database power
> show series
key
---
hiking
solax
> select * from hiking limit 1
name: hiking
time current frequency importEnergy meterErrors voltage
---- ------- --------- ------------ ----------- -------
2018-04-10T14:00:06.663Z 0.16 50.11 27.19 0 247.4
> exit
$
Finally, if I pass influx
a database name on the command line, does that result in the database being created automatically if it doesn't exist?
$ influx -database fred
> show series
ERR: database not found: fred
> show databases
name: databases
name
----
power
weather
airquality
_internal
mydb
> exit
$
And, just to be tidy...
$ influx
> show databases
name: databases
name
----
power
weather
airquality
_internal
mydb
> drop database mydb
> show databases
name: databases
name
----
power
weather
airquality
_internal
> exit
$
Did I actually answer your question somewhere in all of that, or did I miss the point entirely?
I think I might step through all the environment keys in the template and check if each actually exists, then prepare a pull request to clean this up.
@Paraphraser yes, you completely answered my question, thank you for your time and attention. The username fields also don't appear to generate any meaningful usernames, but I think you captured this in your other issue.
It may be something I'm doing wrong.
influxdb.env:
When I docker-compose down and up again, there is no database called mydb - there are the only 2 shown below.
I'm sure it's something I'm doing wrong...