Skip to content

TiDB connector

TiDB speaks the MySQL wire protocol, so Dosi reaches it with the same adapter as MySQL — text protocol, pooled connections, the shared ResultSet normalizer — and compiles SQL for TiDB's MySQL-compatible dialect.

The one thing to get right in the profile is the port: TiDB listens on 4000, not 3306. Gated by the exec-mysql cargo feature.

Connection profile

datasources:
  tidb:
    type: tidb
    host: ${TIDB_HOST}
    port: 4000
    username: dosi
    password: ${TIDB_PASSWORD}
    database: analytics

A mysql:// DSN works too:

    uri: mysql://dosi:${TIDB_PASSWORD}@tidb.internal:4000/analytics

Parameters

Key Type Required Default Notes
type string yes tidb
host string yes* *Unless uri: is given.
port int no 3306 (driver default) TiDB listens on 4000 — set it explicitly.
username string no
password string no Prefer ${VAR}.
database string no
uri string no A mysql:// DSN. It replaces the discrete keys: host, port, username, password and database are ignored when it is set.
default bool no false See connection profiles.

Parsed and ignored on this connector: sslmode, sslrootcert, schema, catalog, arrow_flight_port, account, role, warehouse, compat_mode.

Limitations

  • No FULL OUTER JOIN. Multi-grain merges are lowered to the portable UNION-keys CTE + LEFT JOIN shape instead, so models stay unchanged.
  • No 3-argument DATEDIFF, and no CORR / COVAR_* — both inherited from MySQL compatibility, both refused at compile time rather than approximated.
  • No TLS in this adapter; sslmode/sslrootcert are ignored. TiDB Cloud endpoints that require TLS are therefore not reachable through this connector yet.

Verify the connection

$ dosi query --model model.yaml \
    --metrics revenue --group-by orders.status --execute --connection tidb

Troubleshooting

Message Cause and fix
cannot reach server: <io error> Most often the port: TiDB is 4000, while 3306 may be a different server entirely.
connection "x": bad url: <e> The uri: is not a valid mysql:// DSN.
An auth error carrying TiDB's own text Wrong credentials or missing rights on database:.
server rejected SQL (<code>): <message> TiDB refused the compiled statement.
this build has no tidb executor (feature "exec-mysql" not enabled) TiDB rides the MySQL adapter: --features exec-mysql.

Reference