InfluxDB how to create a database

  • Last update: Apr 3, 2024
  • Views: 62
  • Author: Admin
InfluxDB how to create a database

Colleagues hello to all.

In today's article, we will talk about how to create databases in Influxdb. The very principle of creating a database in Infludb is very similar to how databases are created in MariaDB and Mysql, but there are some differences. DBMS Influxdb belongs to the category of Nosql technologies and supports clustering. Clustering in Infludb is also not the same as in other databases.

I will carry out all actions on version 1.8


Article content:

  1. Connecting to the console.
  2. View all databases.
  3. Create database 
  4. Delete database 
  5. Create retention policy 
  6. Remove data retention policy.
  7. Summary


1. Connecting to the console.

In Influxdb version 1.8, unfortunately there is no graphical interface for managing DBMS, so we will carry out all actions in the console. There is a command to connect to the console:

$. influx



2. View all databases.

To view which melon databases already exist in Influxdb, there is a command:



By default, there is only one database in influxdb, and it is a service database.


3. Create a database.

The process of creating a database in Infludb is very simple. To do this, use the command:

influx> CREATE DATABASE <database name>;



4. Delete the database.

Deleting a database in Influxdb is also very easy. To do this, use the command:

influx> DROP DATABASE <database name>;



5. Create a data retention policy.

The most interesting thing is retention policies, also called RETENTION POLICY. The retention policy is how long Influxdb retains data. By default, when you create a database, the database itself will store data until the disk space runs out. The policy is set on each database separately.

To view what data storage policy you currently have on the database, use the command:

influx> USE test;



We do not pay attention to all the parameters yet, we are interested in the name and duration fields for now.

Whenever you create a database, Influxdb itself will attach a retention policy called autogen, which means that your data will be stored indefinitely, and you will have to manually delete unnecessary data. And to make life easier for us with the retention period of our data we can create our own policy.

To create our own policy, we will use the command:



We have created a retention policy called test_one which will be applied to the test database and our data retention period will be 2 hours. After two hours old data will be automatically deleted from the database. We do not pay attention to REPLICATION 1 yet, it is not so important now.

If you notice, we have the value false in the default field under our newly created policy. This means that the policy seems to be there, but it has not yet been applied to our database. In order for the policy to be applied, let's fix it a little.

influx> ALTER RETENTION POLICY "test_one" ON "test" DEFAULT;


As you can see, now the default field is set to true, which means that the test database has a retention policy called test_one.


6. Remove the retention policy.

Removing policies is also very easy. This will be needed, for example, when you accidentally created a policy with the wrong name.

influx> DROP RETENTION POLICY "bla" ON "test";




7. Results.


Installing Influxdb on Centos 8
Installing Grafana on Centos 8
InfluxDB authentication and authorization