# InfluxDB3 cheatsheet

# InfluxDB 3 client: `influxctl`

[`influxctl`](https://docs.influxdata.com/influxdb3/) is the official command-line tool for managing and interacting with InfluxDB 3 clusters. Think of it as your Swiss Army knife for database setup, bucket management, and query execution.

This cheatsheet gives you a quick reference for the most useful commands, so you don’t need to dig into the docs every time.

---

## Installation

```bash
brew install influxdata/tap/influxctl   # macOS
apt-get install influxctl               # Debian/Ubuntu (if repo available)
```

Check version:

```bash
influxctl version
```

---

## Authentication & Config

Set up your connection profile:

```bash
influxctl config create --host https://cluster-url --org my-org --token my-super-secret-token --active
```

List and manage configs:

```bash
influxctl config list
influxctl config switch my-org
influxctl config delete old-org
```

---

## Buckets

Buckets are where data is stored.

Create a bucket:

```bash
influxctl bucket create --name my-bucket --retention 30d
```

List buckets:

```bash
influxctl bucket list
```

Delete a bucket:

```bash
influxctl bucket delete --name my-bucket
```

---

## Users & Orgs

Create a user:

```bash
influxctl user create --name arpit --password 'securepass'
```

List users:

```bash
influxctl user list
```

Manage orgs:

```bash
influxctl org list
influxctl org create --name team-analytics
```

---

## Writing Data

Write line protocol data directly:

```bash
echo "weather,location=delhi temperature=32.5" | influxctl write --bucket my-bucket
```

Write from a file:

```bash
influxctl write --bucket my-bucket --file data.lp
```

---

## Querying Data

Run a SQL query:

```bash
influxctl query "SELECT * FROM weather LIMIT 10"
```

Export results as JSON:

```bash
influxctl query "SELECT * FROM weather" --format json
```

Save to CSV:

```bash
influxctl query "SELECT time,temperature FROM weather" --format csv > out.csv
```

---

## Tokens

List tokens:

```bash
influxctl auth list
```

Create a read-only token:

```bash
influxctl auth create --read-bucket my-bucket
```

---

## Advanced

* **Profiles for multiple clusters**  
    Easily switch between dev, staging, prod.
    
    ```bash
    influxctl config create --host https://staging-url --org staging --token token123
    influxctl config switch staging
    ```
    
* **Debug connection issues**
    
    ```bash
    influxctl ping
    influxctl health
    ```
    
* **Retention policies**
    
    ```bash
    influxctl bucket update --name my-bucket --retention 7d
    ```
    

---

## Tips

* Keep multiple configs for different clusters and switch quickly with `influxctl config switch`.
    
* Use `--format json` + `jq` for scriptable queries.
    
* Automate backups by exporting queries into CSV on cron.
    

---

With this cheatsheet, you should be able to cover most daily tasks in InfluxDB 3 with just `influxctl`.
