Skip to content

Commit 252814f

Browse files
authored
docs: bendsql dsn (#1950)
* dsn * Update index.md * Update migrating-from-mysql-with-db-archiver.md * Update index.md
1 parent ea30894 commit 252814f

File tree

3 files changed

+149
-19
lines changed

3 files changed

+149
-19
lines changed

docs/en/guides/30-sql-clients/00-bendsql/index.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,98 @@ If you are connecting to a self-hosted Databend instance, you can use the admin
147147

148148
For connections to Databend Cloud, you can use the default `cloudapp` user or an SQL user created with the [CREATE USER](/sql/sql-commands/ddl/user/user-create-user) command. Please note that the user account you use to log in to the [Databend Cloud console](https://app.databend.com/) cannot be used for connecting to Databend Cloud.
149149

150+
## Connecting with BendSQL
151+
152+
BendSQL allows you to connect to both Databend Cloud and self-hosted Databend instances.
153+
154+
### Customize Connections with a DSN
155+
156+
A DSN (Data Source Name) is a simple yet powerful way to configure and manage your Databend connection in BendSQL using a single URI-style string. This method allows you to embed your credentials and connection settings directly into your environment, streamlining the connection process.
157+
158+
#### DSN Format and Parmaeters
159+
160+
```bash title='DSN Format'
161+
databend[+flight]://user[:password]@host[:port]/[database][?sslmode=disable][&arg1=value1]
162+
```
163+
164+
| Common DSN Parameters | Description |
165+
|-----------------------|--------------------------------------|
166+
| `tenant` | Tenant ID, Databend Cloud only. |
167+
| `warehouse` | Warehouse name, Databend Cloud only. |
168+
| `sslmode` | Set to `disable` if not using TLS. |
169+
| `tls_ca_file` | Custom root CA certificate path. |
170+
| `connect_timeout` | Connect timeout in seconds. |
171+
172+
| RestAPI Client Parameters | Description |
173+
|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------|
174+
| `wait_time_secs` | Request wait time for page, default is `1`. |
175+
| `max_rows_in_buffer` | Maximum rows for page buffer. |
176+
| `max_rows_per_page` | Maximum response rows for a single page. |
177+
| `page_request_timeout_secs` | Timeout for a single page request, default is `30`. |
178+
| `presign` | Enable presign for data loading. Options: `auto`, `detect`, `on`, `off`. Default is `auto` (only enabled for Databend Cloud). |
179+
180+
| FlightSQL Client Parameters | Description |
181+
|-----------------------------|----------------------------------------------------------------------|
182+
| `query_timeout` | Query timeout in seconds. |
183+
| `tcp_nodelay` | Defaults to `true`. |
184+
| `tcp_keepalive` | TCP keepalive in seconds (default is `3600`, set to `0` to disable). |
185+
| `http2_keep_alive_interval` | Keep-alive interval in seconds, default is `300`. |
186+
| `keep_alive_timeout` | Keep-alive timeout in seconds, default is `20`. |
187+
| `keep_alive_while_idle` | Defaults to `true`. |
188+
189+
#### DSN Examples
190+
191+
```bash
192+
# Local connection using HTTP API with presign detection
193+
databend://root:@localhost:8000/?sslmode=disable&presign=detect
194+
195+
# Databend Cloud connection with tenant and warehouse info
196+
databend://user1:[email protected]:443/benchmark?enable_dphyp=1
197+
198+
# Local connection using FlightSQL API
199+
databend+flight://root:@localhost:8900/database1?connect_timeout=10
200+
```
201+
202+
### Connect to Databend Cloud
203+
204+
The best practice for connecting to Databend Cloud is to obtain your DSN from Databend Cloud and export it as an environment variable. To obtain your DSN:
205+
206+
1. Log in to Databend Cloud and click **Connect** on the **Overview** page.
207+
208+
2. Select the database and warehouse you want to connect to.
209+
210+
3. Your DSN will be automatically generated in the **Examples** section. Below the DSN, you'll find a BendSQL snippet that exports the DSN as an environment variable named `BENDSQL_DSN` and launches BendSQL with the correct configuration. You can copy and paste it directly into your terminal.
211+
212+
```bash title='Example'
213+
export BENDSQL_DSN="databend://cloudapp:******@tn3ftqihs.gw.aws-us-east-2.default.databend.com:443/information_schema?warehouse=small-xy2t"
214+
bendsql
215+
```
216+
217+
### Connect to Self-hosted Databend
218+
219+
You can connect to a self-hosted Databend instance using either BendSQL command-line arguments or a DSN.
220+
221+
#### Option 1: Use BendSQL Arguments
222+
223+
```bash
224+
bendsql --host <HOST> --port <PORT> --user <USER> --password <PASSWORD> --database <DATABASE>
225+
```
226+
227+
This example connects to a Databend instance running locally on port `8000` using `eric` as the user:
228+
229+
```bash title='Example'
230+
bendsql --host 127.0.0.1 --port 8000 --user eric --password abc123
231+
```
232+
233+
#### Option 2: Use a DSN
234+
235+
You can also define the connection using a DSN and export it as the `BENDSQL_DSN` environment variable:
236+
237+
```bash title='Example'
238+
export BENDSQL_DSN="databend://eric:abc123@localhost:8000/?sslmode=disable"
239+
bendsql
240+
```
241+
150242
## Tutorials
151243
152244
- [Connecting to Self-Hosted Databend using BendSQL](/tutorials/)

docs/en/tutorials/connect/connect-to-databend-bendsql.md

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,92 @@ slug: /
77
import StepsWrap from '@site/src/components/StepsWrap';
88
import StepContent from '@site/src/components/Steps/step-content';
99

10-
In this tutorial, we will guide you through the process of connecting to a self-hosted Databend instance using BendSQL as the user `root`.
10+
In this tutorial, we will guide you through the process of connecting to a self-hosted Databend instance using BendSQL.
1111

1212
<StepsWrap>
1313
<StepContent number="1">
1414

1515
### Before You Start
1616

17+
- Ensure that [Docker](https://www.docker.com/) is installed on your local machine, as it will be used to launch Databend.
1718
- Ensure that BendSQL is installed on your machine. See [Installing BendSQL](/guides/sql-clients/bendsql/#installing-bendsql) for instructions on how to install BendSQL using various package managers.
18-
- Ensure that your Databend instance has started up successfully.
19-
- In this tutorial, you will use the `root` account to connect to Databend. During deployment, uncomment the following lines in the [databend-query.toml](https://github.com/databendlabs/databend/blob/main/scripts/distribution/configs/databend-query.toml) configuration file to select this account:
20-
21-
```sql title="databend-query.toml"
22-
[[query.users]]
23-
name = "root"
24-
auth_type = "no_password"
25-
```
2619

2720
</StepContent>
2821
<StepContent number="2">
2922

30-
### Launch BendSQL
23+
### Start Databend
3124

32-
To launch BendSQL, enter `bendsql` directly into your terminal or command prompt.
25+
Run the following command in your terminal to launch a Databend instance:
3326

34-
:::note
35-
The command `bendsql` launches and connects BendSQL to the local Databend at 127.0.0.1 using the `root` user without requiring a password. If you wish to connect to a local Databend with a different user, such as 'eric' with the password 'abc123', use the command `bendsql --user eric --password abc123`. To view all available arguments and their default values, type `bendsql --help`.
36-
:::
27+
```bash
28+
docker run -d --name databend \
29+
-e QUERY_DEFAULT_USER=eric \
30+
-e QUERY_DEFAULT_PASSWORD=abc123 \
31+
-p 3307:3307 -p 8000:8000 -p 8124:8124 -p 8900:8900 \
32+
datafuselabs/databend:nightly
33+
```
3734

38-
![Alt text](/img/connect/bendsql-1.gif)
35+
This command starts a Databend instance locally in a Docker container with the following connection info:
36+
37+
- Host: `127.0.0.1`
38+
- Port: `8000`
39+
- User: `eric`
40+
- Password: `abc123`
3941

4042
</StepContent>
4143
<StepContent number="3">
4244

45+
### Launch BendSQL
46+
47+
Once the Databend instance is running, you can connect to it using BendSQL. Open a terminal and use the following command to connect:
48+
49+
```bash
50+
bendsql --host 127.0.0.1 --port 8000 --user eric --password abc123
51+
```
52+
53+
This will connect to Databend using the HTTP API at `127.0.0.1:8000` with the user `eric` and the password `abc123`. After running this command, you should see a successful connection message, like the one below:
54+
55+
```bash
56+
Welcome to BendSQL 0.24.7-ff9563a(2024-12-27T03:23:17.723492000Z).
57+
Connecting to 127.0.0.1:8000 as user eric.
58+
Connected to Databend Query v1.2.725-nightly-25ee2d6e65(rust-1.88.0-nightly-2025-04-16T13:54:25.363718584Z)
59+
Loaded 1432 auto complete keywords from server.
60+
Started web server at 127.0.0.1:8080
61+
```
62+
63+
</StepContent>
64+
<StepContent number="4">
65+
4366
### Execute Queries
4467

4568
Once connected, you can execute SQL queries in the BendSQL shell. For instance, type `SELECT NOW();` to return the current time:
4669

47-
![Alt text](/img/connect/bendsql-2.gif)
70+
```bash
71+
[email protected]:8000/default> SELECT NOW();
72+
73+
SELECT NOW()
74+
75+
┌────────────────────────────┐
76+
now() │
77+
│ Timestamp │
78+
├────────────────────────────┤
79+
│ 2025-04-24 13:24:06.640616 │
80+
└────────────────────────────┘
81+
1 row read in 0.025 sec. Processed 1 row, 1 B (40 rows/s, 40 B/s)
82+
```
4883

4984
</StepContent>
50-
<StepContent number="4">
85+
<StepContent number="5">
5186

5287
### Quit BendSQL
5388

5489
To quit BendSQL, type `quit`.
5590

56-
![Alt text](/img/connect/bendsql-3.gif)
91+
```bash
92+
[email protected]:8000/default> quit
93+
Bye~
94+
~
95+
```
5796

5897
</StepContent>
5998
</StepsWrap>

docs/en/tutorials/migrate/migrating-from-mysql-with-db-archiver.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ Download the db-archiver from the [release page](https://github.com/databendclou
126126

127127
```json
128128
{
129-
// Replace the placeholders with your actual values:
130129
"sourceHost": "127.0.0.1",
131130
"sourcePort": 3306,
132131
"sourceUser": "root",

0 commit comments

Comments
 (0)