Skip to content
Docs
Chat2DB CLI
Datasources and SQL

Datasources and SQL

Chat2DB CLI can use the local CLI runtime to read datasources, test connections, create or maintain datasources, and run SQL queries. The default edition is pro; add --edition local when operating Chat2DB Local.

Start by checking state:

chat2db version --json
chat2db status --json

List Datasources

chat2db db datasources --edition pro --json

Show one datasource:

chat2db db datasource --data-source-id <data-source-id> --json

These commands are read-only and do not modify saved datasources.

Test Connections

Test a saved datasource:

chat2db db connection-test --data-source-id <data-source-id> --json

Test MySQL with host fields:

chat2db db connection-test \
  --db-type MYSQL \
  --host localhost \
  --port 3306 \
  --database test \
  --user root \
  --password '<password>' \
  --json

Test with a JDBC URL:

chat2db db connection-test \
  --db-type MYSQL \
  --url 'jdbc:mysql://127.0.0.1:3306/test' \
  --user root \
  --password '<password>' \
  --json

Never expose real passwords in docs, screenshots, or chat logs. JDBC URLs that contain credentials must be redacted.

Create a Datasource

Creating a datasource writes to Chat2DB's saved datasource list. Run connection-test first and create only after the test succeeds.

Create with a JDBC URL:

chat2db db datasource-create \
  --db-type MYSQL \
  --url 'jdbc:mysql://127.0.0.1:3306/test' \
  --user root \
  --password '<password>' \
  --environment-id 1 \
  --json

Create with host fields:

chat2db db datasource-create \
  --db-type MYSQL \
  --host localhost \
  --port 3306 \
  --database test \
  --user root \
  --password '<password>' \
  --environment-id 1 \
  --json

Common environment-id values:

ValueMeaning
1TEST
2RELEASE

Update and Delete Datasources

Update an alias:

chat2db db datasource-update \
  --data-source-id <data-source-id> \
  --alias prod-mysql \
  --json

Delete a datasource:

chat2db db datasource-delete \
  --data-source-id <data-source-id> \
  --yes \
  --json

datasource-delete requires --yes. Confirm the datasource ID and edition before deleting.

Read Database Metadata

List databases:

chat2db db databases --data-source-id <data-source-id> --json

List schemas:

chat2db db schemas \
  --data-source-id <data-source-id> \
  --database postgres \
  --json

List tables:

chat2db db tables \
  --data-source-id <data-source-id> \
  --database postgres \
  --schema public \
  --json

Show table schema:

chat2db db table \
  --data-source-id <data-source-id> \
  --database postgres \
  --schema public \
  --table users \
  --json

Run SQL

Read the first page:

chat2db sql query \
  --data-source-id <data-source-id> \
  --database postgres \
  --schema public \
  --sql 'select 1' \
  --page-no 1 \
  --page-size 100 \
  --json

Select a result set from multi-statement SQL:

chat2db sql query \
  --data-source-id <data-source-id> \
  --database postgres \
  --schema public \
  --sql 'select 1; select 2' \
  --result-set-id 2 \
  --no-row-number \
  --json

The CLI does not decide whether your SQL mutates business data. Before running insert, update, delete, truncate, drop, or similar statements on production, verify the datasource, database, account, and permissions.

Troubleshooting

Runtime Is Unavailable

chat2db runtime status --edition pro --json
chat2db runtime start --edition pro --json

Connection Fails

Use connection-test to isolate host, port, database, user, password, and JDBC URL problems. Common causes include network reachability, account permissions, driver mismatch, or an invalid JDBC URL.

Datasource Is Missing

Check both editions:

chat2db db datasources --edition pro --json
chat2db db datasources --edition local --json