Relational Database (MySQL)
v3.0.0+
The tcb db MySQL command series has been available since v3.0.0.
The tcb db command set provides capabilities for instance management, SQL execution, backup and restore, and slow query monitoring for CloudBase MySQL databases.
tcb db execute
Execute SQL statements (most commonly used command).
tcb db execute --sql '<sql>' [options]
Parameters
| Parameter | Description | Default Value |
|---|---|---|
-s, --sql <sql> | SQL statement to be executed | — |
--readOnly | Execute in read-only mode (suitable for queries, prevents accidental operations) | false |
--instanceId <id> | Instance ID (specify when multiple instances exist) | — |
-e, --env-id <envId> | Environment ID | — |
--json | Output JSON | — |
Example
# Query (Read-Only Mode)
tcb db execute --sql 'SELECT * FROM users LIMIT 10' --readOnly -e my-env-id
# Write Operation
tcb db execute --sql "INSERT INTO orders (user_id, amount) VALUES (1, 99.9)" -e my-env-id
# Query Specific Instance
tcb db execute --sql 'SHOW TABLES' --instanceId inst-xxx --readOnly -e my-env-id
tcb db instance list
List MySQL instances in the current environment.
tcb db instance list [options]
Parameters
| Parameter | Description | Default Value |
|---|---|---|
--limit <n> | Number of returned items | 20 |
--offset <n> | Offset | 0 |
--instanceId <id> | Filter by instance ID | — |
-e, --env-id <envId> | Environment ID | — |
tcb db instance config
Query or modify MySQL instance configuration (reconfigure).
# Query Instance Configuration
tcb db instance config --instanceId <id> [options]
# Modify Instance Configuration (Reconfigure)
tcb db instance config --instanceId <id> --cpu <n> --memory <gb> [options]
Parameters
| Parameter | Description | Optional Values |
|---|---|---|
--instanceId <id> | Instance ID | — |
--cpu <n> | CPU cores | 1 / 2 / 4 / 8 / 16 |
--memory <gb> | Memory size (GB) | 2 / 4 / 8 / 16 / 32 / 64 / 128 |
tcb db instance restart
Restart MySQL instance.
tcb db instance restart --instanceId <id> [options]
Backup Management
tcb db backup create
Create MySQL backup.
tcb db backup create [options]
| Parameter | Description | Required |
|---|---|---|
--type <type> | Backup type: snapshot (snapshot) / logic (logical backup) | — |
--databases <names> | List of databases to back up, comma-separated (only valid for logical backups) | — |
--name <name> | Backup remark name | — |
--instanceId <id> | Instance ID | — |
# Create Snapshot Backup
tcb db backup create --type snapshot --name "Pre-release Backup" --instanceId inst-xxx -e my-env-id
# Logical Backup of Specified Databases
tcb db backup create --type logic --databases "db1,db2" --instanceId inst-xxx -e my-env-id
tcb db backup list
List backup records.
tcb db backup list [--startTime <time>] [--endTime <time>] [options]
tcb db backup restore
Restore backup (cluster rollback).
tcb db backup restore [options]
| Parameter | Description | Required |
|---|---|---|
--strategy <strategy> | Rollback policy: snapRollback (by backup) / timeRollback (by point in time) | ✅ |
--backupId <id> | Backup file ID (required when rolling back by backup) | Conditional |
--expectTime <time> | Expected rollback time (required when rolling back by point in time, format: 2026-03-10 14:00:00) | Conditional |
--instanceId <id> | Instance ID | — |
# Rollback by Backup ID
tcb db backup restore \
--strategy snapRollback \
--backupId backup-xxx \
--instanceId inst-xxx \
-e my-env-id
# Rollback by Point in Time
tcb db backup restore \
--strategy timeRollback \
--expectTime "2026-03-10 14:00:00" \
--instanceId inst-xxx \
-e my-env-id
tcb db backup delete
Delete specified backup.
tcb db backup delete --backupId <id> [options]
Slow Query Monitoring
tcb db monitor slow-log
View slow query logs with support for time range and multi-dimensional filtering.
tcb db monitor slow-log [options]
| Parameter | Description |
|---|---|
--start <time> | Start time (e.g. 2026-03-01 00:00:00) |
--end <time> | End Time |
--threshold <seconds> | Slow query threshold (seconds), local filtering, e.g. 1 |
--orderBy <field> | Sort field: QueryTime / LockTime / RowsExamined / RowsSent |
--orderByType <order> | Sort order: asc / desc |
--database <name> | Filter by database name |
--username <name> | Filter by username |
--instanceId <id> | Instance ID |
-e, --env-id <envId> | Environment ID |
# View slow queries in the past 24h, sorted by execution time in descending order.
tcb db monitor slow-log \
--start "2026-03-29 00:00:00" \
--end "2026-03-30 00:00:00" \
--orderBy QueryTime \
--orderByType desc \
--threshold 1 \
-e my-env-id