MySQL Read-Only Query Skill
Execute safe, read-only queries against configured MySQL databases.
Requirements
- Python 3.8+
- mysql-connector-python:
pip install -r requirements.txt
Setup
Create connections.json in the skill directory or ~/.config/claude/mysql-connections.json.
Security: Set file permissions to 600 since it contains credentials:
chmod 600 connections.json
{
"databases": [
{
"name": "production",
"description": "Main app database - users, orders, transactions",
"host": "db.example.com",
"port": 3306,
"database": "app_prod",
"user": "readonly_user",
"password": "your-password",
"ssl_disabled": false
}
]
}
Config Fields
| Field |
Required |
Description |
| name |
Yes |
Identifier for the database (case-insensitive) |
| description |
Yes |
What data this database contains (used for auto-selection) |
| host |
Yes |
Database hostname |
| port |
No |
Port number (default: 3306) |
| database |
Yes |
Database name |
| user |
Yes |
Username |
| password |
Yes |
Password |
| ssl_disabled |
No |
Set to true to disable SSL (default: false) |
| ssl_ca |
No |
Path to CA certificate file |
| ssl_cert |
No |
Path to client certificate file |
| ssl_key |
No |
Path to client private key file |
Usage
List configured databases
python3 scripts/query.py --list
Query a database
python3 scripts/query.py --db production --query "SELECT * FROM users LIMIT 10"
List tables
python3 scripts/query.py --db production --tables
Show schema
python3 scripts/query.py --db production --schema
Limit results
python3 scripts/query.py --db production --query "SELECT * FROM orders" --limit 100
Database Selection
Match user intent to database description:
| User asks about |
Look for description containing |
| users, accounts |
users, accounts, customers |
| orders, sales |
orders, transactions, sales |
| analytics, metrics |
analytics, metrics, reports |
| logs, events |
logs, events, audit |
If unclear, run --list and ask user which database.
Safety Features
- Read-only session: Connection uses MySQL
SET SESSION TRANSACTION READ ONLY (primary protection)
- Query validation: Only SELECT, SHOW, DESCRIBE, EXPLAIN, WITH queries allowed
- Single statement: Multiple statements per query rejected
- SSL support: Configurable SSL with CA, client cert, and key support
- Query timeout: 30-second max_execution_time enforced (MySQL 5.7.8+)
- Memory protection: Max 10,000 rows per query to prevent OOM
- Column width cap: 100 char max per column for readable output
- Credential sanitization: Error messages don't leak passwords
Troubleshooting
| Error |
Solution |
| Config not found |
Create connections.json in skill directory |
| Authentication failed |
Check username/password in config |
| Connection timeout |
Verify host/port, check firewall/VPN |
| SSL error |
Try "ssl_disabled": true for local databases |
| Permission warning |
Run chmod 600 connections.json |
| max_execution_time not supported |
Upgrade to MySQL 5.7.8+ or MariaDB 10.1.1+ |
Exit Codes
- 0: Success
- 1: Error (config missing, auth failed, invalid query, database error)
Workflow
- Run
--list to show available databases
- Match user intent to database description
- Run
--tables or --schema to explore structure
- Execute query with appropriate LIMIT
1---2name: mysql3description: Execute read-only SQL queries against multiple MySQL databases. Use when: (1) querying MySQL databases, (2) exploring database schemas/tables, (3) running SELECT queries for data analysis, (4) checking database contents. Supports multiple database connections with descriptions for intelligent auto-selection. Blocks all write operations (INSERT, UPDATE, DELETE, DROP, etc.) for safety.4license: Apache-2.05---67# MySQL Read-Only Query Skill89Execute safe, read-only queries against configured MySQL databases.1011## Requirements1213- Python 3.8+14- mysql-connector-python: `pip install -r requirements.txt`1516## Setup1718Create `connections.json` in the skill directory or `~/.config/claude/mysql-connections.json`.1920**Security**: Set file permissions to `600` since it contains credentials:21```bash22chmod 600 connections.json23```2425```json26{27 "databases": [28 {29 "name": "production",30 "description": "Main app database - users, orders, transactions",31 "host": "db.example.com",32 "port": 3306,33 "database": "app_prod",34 "user": "readonly_user",35 "password": "your-password",36 "ssl_disabled": false37 }38 ]39}40```4142### Config Fields4344| Field | Required | Description |45|-------|----------|-------------|46| name | Yes | Identifier for the database (case-insensitive) |47| description | Yes | What data this database contains (used for auto-selection) |48| host | Yes | Database hostname |49| port | No | Port number (default: 3306) |50| database | Yes | Database name |51| user | Yes | Username |52| password | Yes | Password |53| ssl_disabled | No | Set to `true` to disable SSL (default: false) |54| ssl_ca | No | Path to CA certificate file |55| ssl_cert | No | Path to client certificate file |56| ssl_key | No | Path to client private key file |5758## Usage5960### List configured databases61```bash62python3 scripts/query.py --list63```6465### Query a database66```bash67python3 scripts/query.py --db production --query "SELECT * FROM users LIMIT 10"68```6970### List tables71```bash72python3 scripts/query.py --db production --tables73```7475### Show schema76```bash77python3 scripts/query.py --db production --schema78```7980### Limit results81```bash82python3 scripts/query.py --db production --query "SELECT * FROM orders" --limit 10083```8485## Database Selection8687Match user intent to database `description`:8889| User asks about | Look for description containing |90|-----------------|--------------------------------|91| users, accounts | users, accounts, customers |92| orders, sales | orders, transactions, sales |93| analytics, metrics | analytics, metrics, reports |94| logs, events | logs, events, audit |9596If unclear, run `--list` and ask user which database.9798## Safety Features99100- **Read-only session**: Connection uses MySQL `SET SESSION TRANSACTION READ ONLY` (primary protection)101- **Query validation**: Only SELECT, SHOW, DESCRIBE, EXPLAIN, WITH queries allowed102- **Single statement**: Multiple statements per query rejected103- **SSL support**: Configurable SSL with CA, client cert, and key support104- **Query timeout**: 30-second max_execution_time enforced (MySQL 5.7.8+)105- **Memory protection**: Max 10,000 rows per query to prevent OOM106- **Column width cap**: 100 char max per column for readable output107- **Credential sanitization**: Error messages don't leak passwords108109## Troubleshooting110111| Error | Solution |112|-------|----------|113| Config not found | Create `connections.json` in skill directory |114| Authentication failed | Check username/password in config |115| Connection timeout | Verify host/port, check firewall/VPN |116| SSL error | Try `"ssl_disabled": true` for local databases |117| Permission warning | Run `chmod 600 connections.json` |118| max_execution_time not supported | Upgrade to MySQL 5.7.8+ or MariaDB 10.1.1+ |119120## Exit Codes121122- **0**: Success123- **1**: Error (config missing, auth failed, invalid query, database error)124125## Workflow1261271. Run `--list` to show available databases1282. Match user intent to database description1293. Run `--tables` or `--schema` to explore structure1304. Execute query with appropriate LIMIT