Search code examples
influxdb

How to drop all InfluxDB databases?


I am trying to drop all of the InfluxDB databases except the _internal one as I do not want to do this every time manually, however, this is not supported directly from influxdb. I was considering writing a shell script for this, however, I was not able to list all of the databases in order to pipe them to the DROP DATABASE <db_name> command. Every suggestion would be helpful!


Solution

  • To answer my own question, I went for a short python script using influxdb -

    from influxdb import InfluxDBClient
    import os
    
    influx_host = os.getenv('INFLUX_HOST', 'localhost')
    db_client = InfluxDBClient(host=influx_host)
    
    db_list = db_client.get_list_database()
    
    for db in db_list:
        db_client.drop_database(db['name'])