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:
- 1. Search Target Database — Search databases by keyword to get Database ID
- Execute SQL Query — Execute SQL statements on the target database
Architecture
CODEBLOCK0
Prerequisites
Pre-check: Aliyun CLI >= 3.3.1 required
Run aliyun version to verify >= 3.3.1. If not installed or version too low,
see references/cli-installation-guide.md for installation instructions.
Then [MUST] run aliyun configure set --auto-plugin-install true to enable automatic plugin installation.
- - Aliyun CLI >= 3.3.1
- jq (for JSON parsing): INLINECODE3
- Credentials configured via INLINECODE4
Pre-check: Alibaba Cloud Credentials Required
Security Rules:
- - NEVER read, echo, or print AK/SK values (e.g.,
echo $ALIBABA_CLOUD_ACCESS_KEY_ID is FORBIDDEN) - NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use
aliyun configure set with literal credential values - ONLY use
aliyun configure list to check credential status
> aliyun configure list
>
Check the output for a valid profile (AK, STS, or OAuth identity).
If no valid profile exists, STOP here.
- 1. Obtain credentials from Alibaba Cloud Console
- Configure credentials outside of this session (via
aliyun configure in terminal or environment variables in shell profile) - Return and re-run after
aliyun configure list shows a valid profile
RAM Permissions
[MUST] RAM Permission Pre-check: Verify that the current user has the following RAM permissions before execution.
See references/ram-policies.md for the complete permission list.
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 | - |
| db-id |
Required | Database ID (obtained from search results) | - |
| sql | Required | SQL statement to execute | - |
| logic | Optional | Whether to use logic database mode | false |
Core Workflow
Task 1: Search Target Database
Search for databases by keyword to get the Database ID:
CODEBLOCK2
Example:
CODEBLOCK3
The output includes database_id, schema_name, db_type, host, port, etc.
Task 2: Execute SQL Query
Execute SQL using the Database ID obtained in the previous step:
CODEBLOCK4
Examples:
CODEBLOCK5
Complete Example
CODEBLOCK6
Success Verification
After executing SQL, check the returned results:
- 1. Script return code is 0
- Output contains query results (column names and row data)
- No error messages
CODEBLOCK7
Cleanup
This skill only performs query operations and does not create resources. No cleanup is required.
Available Scripts
| Script | Description |
|---|
| INLINECODE16 | Search databases by keyword |
| INLINECODE17 |
Execute SQL queries |
Note: Scripts use aliyun-cli credentials configured via aliyun configure.
Best Practices
- 1. Confirm database — Verify the target database before executing SQL
- Use --json parameter — Facilitates programmatic processing of output
- Be cautious with sensitive operations — For UPDATE/DELETE operations, execute SELECT first to confirm
Reference Links
RAM Permission Policies |
|
references/related-apis.md | Related API List |
|
references/acceptance-criteria.md | Acceptance Criteria |
阿里云DMS数据库读写
通过阿里云DMS OpenAPI搜索目标数据库并执行SQL查询和数据修改。
场景描述
该技能实现以下工作流程:
- 1. 搜索目标数据库 — 通过关键词搜索数据库,获取数据库ID
- 执行SQL查询 — 在目标数据库上执行SQL语句
架构
用户请求 → 搜索数据库 → 获取数据库ID → 执行SQL → 返回结果
前置条件
预检查:需要Aliyun CLI >= 3.3.1
运行 aliyun version 确认版本 >= 3.3.1。如果未安装或版本过低,
请参阅 references/cli-installation-guide.md 获取安装说明。
然后[必须]运行 aliyun configure set --auto-plugin-install true 启用自动插件安装。
- - Aliyun CLI >= 3.3.1
- jq(用于JSON解析):brew install jq
- 通过 aliyun configure 配置的凭证
预检查:需要阿里云凭证
安全规则:
- - 禁止读取、回显或打印AK/SK值(例如,echo $ALIBABACLOUDACCESSKEYID 是被禁止的)
- 禁止要求用户在对话或命令行中直接输入AK/SK
- 禁止使用字面凭证值执行 aliyun configure set
- 仅允许使用 aliyun configure list 检查凭证状态
bash
aliyun configure list
检查输出中是否存在有效的配置文件(AK、STS或OAuth身份)。
如果没有有效的配置文件,请在此处停止。
- 1. 从阿里云控制台获取凭证
- 在此会话之外配置凭证(通过终端中的 aliyun configure 或shell配置文件中的环境变量)
- 在 aliyun configure list 显示有效配置文件后返回并重新运行
RAM权限
[必须] RAM权限预检查: 在执行前确认当前用户具有以下RAM权限。
请参阅 references/ram-policies.md 获取完整权限列表。
参数确认
重要提示:参数确认 — 在执行任何命令或API调用之前,
所有用户可自定义的参数(例如,数据库关键词、SQL语句、数据库ID等)
必须与用户确认。未经用户明确批准,不得假设或使用默认值。
| 参数 | 必填/可选 | 描述 | 默认值 |
|---|
| keyword | 必填 | 数据库搜索关键词 | - |
| db-id |
必填 | 数据库ID(从搜索结果中获取) | - |
| sql | 必填 | 要执行的SQL语句 | - |
| logic | 可选 | 是否使用逻辑数据库模式 | false |
核心工作流程
任务1:搜索目标数据库
通过关键词搜索数据库,获取数据库ID:
bash
./scripts/search_database.sh --json
示例:
bash
搜索包含mydb的数据库
./scripts/search_database.sh mydb --json
输出包含 databaseid、schemaname、db_type、host、port 等。
任务2:执行SQL查询
使用上一步获取的数据库ID执行SQL:
bash
./scripts/executequery.sh --db-id id> --sql
示例:
bash
列出表
./scripts/execute_query.sh --db-id 78059000 --sql SHOW TABLES
查询数据并输出JSON
./scripts/execute_query.sh --db-id 78059000 --sql SELECT * FROM users LIMIT 10 --json
逻辑数据库模式
./scripts/execute_query.sh --db-id 78059000 --sql SELECT 1 --logic
完整示例
bash
1. 搜索数据库(假设搜索order)
./scripts/search_database.sh order --json
示例输出:
[{DatabaseId: 78059000, SchemaName: order_db, ...}]
2. 执行查询
./scripts/execute_query.sh --db-id 78059000 --sql SELECT COUNT(*) FROM orders
成功验证
执行SQL后,检查返回结果:
- 1. 脚本返回码为0
- 输出包含查询结果(列名和行数据)
- 无错误消息
bash
验证查询成功
./scripts/execute_query.sh --db-id
--sql SELECT 1 --json
预期输出:[{Success: true, RowCount: 1, ...}]
清理
该技能仅执行查询操作,不创建资源。无需清理。
可用脚本
| 脚本 | 描述 |
|---|
| scripts/searchdatabase.sh | 通过关键词搜索数据库 |
| scripts/executequery.sh |
执行SQL查询 |
注意: 脚本使用通过 aliyun configure 配置的aliyun-cli凭证。
最佳实践
- 1. 确认数据库 — 在执行SQL前验证目标数据库
- 使用--json参数 — 便于程序化处理输出
- 谨慎处理敏感操作 — 对于UPDATE/DELETE操作,先执行SELECT确认
参考链接
RAM权限策略 |
| references/related-apis.md | 相关API列表 |
| references/acceptance-criteria.md | 验收标准 |