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 --jsonList Datasources
chat2db db datasources --edition pro --jsonShow one datasource:
chat2db db datasource --data-source-id <data-source-id> --jsonThese 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> --jsonTest MySQL with host fields:
chat2db db connection-test \
--db-type MYSQL \
--host localhost \
--port 3306 \
--database test \
--user root \
--password '<password>' \
--jsonTest with a JDBC URL:
chat2db db connection-test \
--db-type MYSQL \
--url 'jdbc:mysql://127.0.0.1:3306/test' \
--user root \
--password '<password>' \
--jsonNever 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 \
--jsonCreate with host fields:
chat2db db datasource-create \
--db-type MYSQL \
--host localhost \
--port 3306 \
--database test \
--user root \
--password '<password>' \
--environment-id 1 \
--jsonCommon environment-id values:
| Value | Meaning |
|---|---|
1 | TEST |
2 | RELEASE |
Update and Delete Datasources
Update an alias:
chat2db db datasource-update \
--data-source-id <data-source-id> \
--alias prod-mysql \
--jsonDelete a datasource:
chat2db db datasource-delete \
--data-source-id <data-source-id> \
--yes \
--jsondatasource-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> --jsonList schemas:
chat2db db schemas \
--data-source-id <data-source-id> \
--database postgres \
--jsonList tables:
chat2db db tables \
--data-source-id <data-source-id> \
--database postgres \
--schema public \
--jsonShow table schema:
chat2db db table \
--data-source-id <data-source-id> \
--database postgres \
--schema public \
--table users \
--jsonRun 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 \
--jsonSelect 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 \
--jsonThe 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 --jsonConnection 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