Database Tools
Overview
This skill combines tools for PostgreSQL, MySQL, and Microsoft SQL Server (MSSQL).
Capabilities/Tools
You have three specialized query scripts located in scripts/:
- PostgreSQL:
scripts/postgres_query.py
- MySQL:
scripts/mysql_query.py
- MSSQL:
scripts/mssql_query.py
These scripts allow you to securely connect to a database using predefined alias configurations, execute read/write queries, explain plans, and format output. DO NOT attempt to write your own psycopg2 or pymysql wrappers; always use these scripts unless explicitly told otherwise.
Permissions & Safety
The query scripts analyze every SQL statement before execution. Read-only queries (SELECT, SHOW, EXPLAIN) will execute directly. Write queries (INSERT, UPDATE, DELETE, DROP, ALTER, etc.) will NOT execute implicitly.
Setup
- Check if
connections.json exists in the skill root or your working directory. If it doesn't exist, create it from connections.example.json.
- Add the user's database credentials securely to
connections.json. The user must either provide these or tell you where to find them. Do NOT guess passwords.
- Identify the connection by its top-level alias (e.g.,
prod_db, local_test).
Usage
PostgreSQL (postgres_query.py)
python scripts/postgres_query.py <connection_name> "<sql_query>" [--json] [--explain]
MySQL (mysql_query.py)
python scripts/mysql_query.py <connection_name> "<sql_query>" [--json] [--explain]
MSSQL (mssql_query.py)
python scripts/mssql_query.py <connection_name> "<sql_query>" [--json] [--explain]
Best Practices
- Explore First: Start by describing the database schema. Example:
SELECT table_name FROM information_schema.tables WHERE table_schema='public';
- Limit Rows: Always use
LIMIT N or TOP N on initial SELECT queries to avoid massive outputs crashing your context window.
- Write Operations: For state-changing operations, ensure you double-check conditions (e.g., proper
WHERE clauses). The script will prompt for safety or block you based on configuration—follow the script's instructions.
1---2name: database-tools-23domain: infrastructure4skill_type: skill5description: >-6 Use this skill whenever the user wants to connect to, query, or manage7 databases, including PostgreSQL, MySQL, and MS SQL Server (MSSQL). Requires8 setting up a connections.json file with credentials. Can execute SQL queries,9 inspect schemas, dump data, and repair broken tables depending on dialect.10license: MIT11tags: [database, sql, postgresql, mysql, mssql, querying, schema, data-extraction]12metadata:13 source: https://skillmd.com/skills/knuckles-team/database-tools-214 version: '1.6.0'15 author: Genius16---1718# Database Tools1920## Overview21This skill combines tools for PostgreSQL, MySQL, and Microsoft SQL Server (MSSQL).2223## Capabilities/Tools2425You have three specialized query scripts located in `scripts/`:26- **PostgreSQL**: `scripts/postgres_query.py`27- **MySQL**: `scripts/mysql_query.py`28- **MSSQL**: `scripts/mssql_query.py`2930These scripts allow you to securely connect to a database using predefined alias configurations, execute read/write queries, explain plans, and format output. DO NOT attempt to write your own `psycopg2` or `pymysql` wrappers; always use these scripts unless explicitly told otherwise.3132## Permissions & Safety33The query scripts analyze every SQL statement before execution. Read-only queries (`SELECT`, `SHOW`, `EXPLAIN`) will execute directly. Write queries (`INSERT`, `UPDATE`, `DELETE`, `DROP`, `ALTER`, etc.) will NOT execute implicitly.3435## Setup361. Check if `connections.json` exists in the skill root or your working directory. If it doesn't exist, create it from `connections.example.json`.372. Add the user's database credentials securely to `connections.json`. The user must either provide these or tell you where to find them. Do NOT guess passwords.383. Identify the connection by its top-level alias (e.g., `prod_db`, `local_test`).3940## Usage4142### PostgreSQL (`postgres_query.py`)43```bash44python scripts/postgres_query.py <connection_name> "<sql_query>" [--json] [--explain]45```4647### MySQL (`mysql_query.py`)48```bash49python scripts/mysql_query.py <connection_name> "<sql_query>" [--json] [--explain]50```5152### MSSQL (`mssql_query.py`)53```bash54python scripts/mssql_query.py <connection_name> "<sql_query>" [--json] [--explain]55```5657## Best Practices581. **Explore First**: Start by describing the database schema. Example: `SELECT table_name FROM information_schema.tables WHERE table_schema='public';`592. **Limit Rows**: Always use `LIMIT N` or `TOP N` on initial `SELECT` queries to avoid massive outputs crashing your context window.603. **Write Operations**: For state-changing operations, ensure you double-check conditions (e.g., proper `WHERE` clauses). The script will prompt for safety or block you based on configuration—follow the script's instructions.