TiDB Zero (Temporary / Playground Database)
Goal
Create a temporary/playground TiDB database via one HTTP API.
Setup (env + tools)
Required env:
- •
TIDBZERO_HOST: API host (no auth) - •
TIDB0_INVITATION_CODE: invitation code for create-db
Optional env:
- •
TIDBZERO_BASE_PATH(default/v1alpha1) - •
TIDB0_NAME_PREFIX(optional) - •
TIDB0_DB_PASSWORD(optional)
Timeout env:
- •
TIDB0_CURL_CONNECT_TIMEOUT(default10) - •
TIDB0_CURL_MAX_TIME(default60)
Prereqs:
- •HTTP:
curl(and optionallyjqfor pretty-print) - •SQL:
mysqlsh(preferred) ormysql
API: Create a temporary database (playground-like)
Base URL:
BASE="https://${TIDBZERO_HOST}${TIDBZERO_BASE_PATH:-/v1alpha1}"
Request body (required: invitationCode; optional: namePrefix, password):
body='{"invitationCode":"'"${TIDB0_INVITATION_CODE}"'","namePrefix":"'"${TIDB0_NAME_PREFIX:-}"'"}'
If you want to set a password (optional):
body='{"invitationCode":"'"${TIDB0_INVITATION_CODE}"'","namePrefix":"'"${TIDB0_NAME_PREFIX:-}"'","password":"'"${TIDB0_DB_PASSWORD}"'"}'
Call (current spec uses POST /instances):
curl -sS -X POST \
-H 'content-type: application/json' \
--connect-timeout "${TIDB0_CURL_CONNECT_TIMEOUT:-10}" \
--max-time "${TIDB0_CURL_MAX_TIME:-60}" \
--data-binary "$body" \
"${BASE}/instances"
If you want pretty JSON (optional jq):
curl -sS -X POST \
-H 'content-type: application/json' \
--connect-timeout "${TIDB0_CURL_CONNECT_TIMEOUT:-10}" \
--max-time "${TIDB0_CURL_MAX_TIME:-60}" \
--data-binary "$body" \
"${BASE}/instances" | jq .
On success, ALWAYS explicitly print these fields to the user (in addition to the full JSON response):
- •
id,name,expiresAt,remainingDatabaseQuota - •
connection.host,connection.port,connection.username,connection.password
Follow-up: Run SQL on the created database
Use returned connection.
mysqlsh (preferred; password via stdin). In sandboxed environments, set MYSQLSH_USER_CONFIG_HOME to a writable directory:
mkdir -p /tmp/mysqlsh-codex printf '%s' '<connection.password>' | MYSQLSH_USER_CONFIG_HOME=/tmp/mysqlsh-codex mysqlsh --sql \ --host '<connection.host>' --port '<connection.port>' --user '<connection.username>' \ --passwords-from-stdin \ --execute "SELECT 1;"
mysql fallback:
MYSQL_PWD='<connection.password>' mysql \ -h '<connection.host>' -P '<connection.port>' -u '<connection.username>' \ -e "SELECT 1;"