alibabacloud-dms-skill
Original:🇺🇸 English
Translated
2 scripts
Alibaba Cloud DMS Database Read/Write Skill. Use this skill to search for target databases in DMS and execute SQL queries and data modifications. Triggers: "DMS query", "database query", "execute SQL", "search database", "DMS SQL", "insert data", "update data".
4installs
Added on
NPX Install
npx skill4agent add aliyun/alibabacloud-aiops-skills alibabacloud-dms-skillTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Alibaba Cloud DMS Database Read/Write
Search for target databases and execute SQL queries and data modifications via Alibaba Cloud DMS OpenAPI.
Scenario Description
This skill implements the following workflow:
- Search Target Database — Search databases by keyword to get Database ID
- Execute SQL Query — Execute SQL statements on the target database
Architecture
User Request → Search Database → Get Database ID → Execute SQL → Return ResultsPrerequisites
Pre-check: Aliyun CLI >= 3.3.1 required Runto verify >= 3.3.1. If not installed or version too low, seealiyun versionfor installation instructions. Then [MUST] runreferences/cli-installation-guide.mdto enable automatic plugin installation.aliyun configure set --auto-plugin-install true
- Aliyun CLI >= 3.3.1
- jq (for JSON parsing):
brew install jq - Credentials configured via
aliyun configure
Pre-check: Alibaba Cloud Credentials RequiredSecurity Rules:
- NEVER read, echo, or print AK/SK values (e.g.,
is FORBIDDEN)echo $ALIBABA_CLOUD_ACCESS_KEY_ID- NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use
with literal credential valuesaliyun configure set- ONLY use
to check credential statusaliyun configure listbashaliyun configure listCheck the output for a valid profile (AK, STS, or OAuth identity).If no valid profile exists, STOP here.
- Obtain credentials from Alibaba Cloud Console
- Configure credentials outside of this session (via
in terminal or environment variables in shell profile)aliyun configure- Return and re-run after
shows a valid profilealiyun configure list
RAM Permissions
[MUST] RAM Permission Pre-check: Verify that the current user has the following RAM permissions before execution. Seefor the complete permission list.references/ram-policies.md
Parameter Confirmation
IMPORTANT: Parameter Confirmation — Before executing any command or API call, ALL user-customizable parameters (e.g., database keyword, SQL statement, db-id, etc.) MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.
| Parameter | Required/Optional | Description | Default |
|---|---|---|---|
| keyword | Required | Database search keyword (1-128 chars, alphanumeric) | - |
| db-id | Required | Database ID (positive integer, obtained from search) | - |
| sql | Required | SQL statement to execute (1-10000 chars) | - |
| logic | Optional | Whether to use logic database mode | false |
| force | Optional | Confirm write operations (INSERT/UPDATE/DELETE) | false |
| dry-run | Optional | Preview write operations without executing | false |
Core Workflow
Task 1: Search Target Database
Search for databases by keyword to get the Database ID:
bash
./scripts/search_database.sh <keyword> --jsonExample:
bash
# Search for databases containing "mydb"
./scripts/search_database.sh mydb --jsonThe output includes , , , , , etc.
database_idschema_namedb_typehostportTask 2: Execute SQL Query
Execute SQL using the Database ID obtained in the previous step:
bash
./scripts/execute_query.sh --db-id <database_id> --sql "<SQL_statement>"Write Operation Protection
For write operations (INSERT/UPDATE/DELETE), the script implements protective pre-check:
| Parameter | Description |
|---|---|
| Required to confirm and execute write operations |
| Preview write operations without executing |
DDL Operations (DROP/TRUNCATE/ALTER/RENAME) are completely blocked — these must be executed via DMS Console.
Examples:
bash
# Read operations (no confirmation needed)
./scripts/execute_query.sh --db-id 78059000 --sql "SHOW TABLES"
./scripts/execute_query.sh --db-id 78059000 --sql "SELECT * FROM users LIMIT 10" --json
# Write operations - preview first (recommended)
./scripts/execute_query.sh --db-id 78059000 --sql "INSERT INTO users (name) VALUES ('test')" --dry-run
# Write operations - execute with confirmation
./scripts/execute_query.sh --db-id 78059000 --sql "INSERT INTO users (name) VALUES ('test')" --force
./scripts/execute_query.sh --db-id 78059000 --sql "UPDATE users SET name='test' WHERE id=1" --force
./scripts/execute_query.sh --db-id 78059000 --sql "DELETE FROM users WHERE id=1" --force
# Logic database mode
./scripts/execute_query.sh --db-id 78059000 --sql "SELECT 1" --logicComplete Example
bash
# 1. Search database (assuming searching for "order")
./scripts/search_database.sh order --json
# Example output:
# [{"DatabaseId": "78059000", "SchemaName": "order_db", ...}]
# 2. Execute query
./scripts/execute_query.sh --db-id 78059000 --sql "SELECT COUNT(*) FROM orders"Success Verification
After executing SQL, check the returned results:
- Script return code is 0
- Output contains query results (column names and row data)
- No error messages
bash
# Verify query success
./scripts/execute_query.sh --db-id <db-id> --sql "SELECT 1" --json
# Expected output: [{"Success": true, "RowCount": 1, ...}]Cleanup
This skill performs read and write operations but does not create persistent resources. No cleanup is required.
Write Operation Safety
| Operation Type | Behavior |
|---|---|
| SELECT / SHOW / DESC | Execute directly |
| INSERT / UPDATE / DELETE | Require |
| DROP / TRUNCATE / ALTER / RENAME | Blocked — use DMS Console |
Available Scripts
| Script | Description |
|---|---|
| Search databases by keyword |
| Execute SQL queries |
Note: Scripts use aliyun-cli credentials configured via.aliyun configure
Best Practices
- Confirm database — Verify the target database before executing SQL
- Use --json parameter — Facilitates programmatic processing of output
- Preview write operations — Always use first for INSERT/UPDATE/DELETE
--dry-run - Explicit confirmation — Use only after reviewing the preview
--force - Avoid DDL operations — DROP/TRUNCATE/ALTER/RENAME are blocked; use DMS Console instead
Reference Links
| Document | Description |
|---|---|
| references/cli-installation-guide.md | CLI Installation Guide |
| references/ram-policies.md | RAM Permission Policies |
| references/related-apis.md | Related API List |
| references/acceptance-criteria.md | Acceptance Criteria |