home / skills / microck / ordinary-claude-skills / sql

This skill runs SQL queries against WordPress development databases, helping you inspect data, debug issues, and analyze history tables efficiently.

npx playbooks add skill microck/ordinary-claude-skills --skill sql

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
2.2 KB
---
name: sql
description: Run SQL queries against the WordPress development database. Use when querying database tables, inspecting Simple History events, checking WordPress data, or debugging database issues.
---

# Run SQL Queries

You are tasked with running SQL queries against the WordPress development database.

## Prerequisites

- Database credentials are stored in `CLAUDE.local.md` under "Database Access"
- Docker compose services must be running
- Commands must be run from the docker-compose project directory

## Command Pattern

```bash
docker compose exec mariadb mysql -u<USER> -p<PASSWORD> <DATABASE> -e "YOUR_SQL_HERE"
```

Refer to `CLAUDE.local.md` for the actual credentials and connection details.

## Examples

### Show all tables
```bash
docker compose exec mariadb mysql -u<USER> -p<PASSWORD> <DATABASE> -e "SHOW TABLES;"
```

### Query Simple History events
```bash
docker compose exec mariadb mysql -u<USER> -p<PASSWORD> <DATABASE> -e "SELECT * FROM wp_simple_history ORDER BY id DESC LIMIT 10;"
```

### Describe a table structure
```bash
docker compose exec mariadb mysql -u<USER> -p<PASSWORD> <DATABASE> -e "DESCRIBE wp_simple_history;"
```

### Count records
```bash
docker compose exec mariadb mysql -u<USER> -p<PASSWORD> <DATABASE> -e "SELECT COUNT(*) FROM wp_posts;"
```

## Table Prefixes

The database contains multiple WordPress installations with different prefixes:

| Prefix | Installation |
|--------|--------------|
| `wp_` | Main install (wordpress_mariadb) |
| `wp_nightly_` | Nightly build |
| `wp_6_0_` to `wp_6_6_` | Version-specific installs |
| `wp_multisite_` | Multisite install |
| `wp_php74_` | PHP 7.4 install |
| `wp_subfolder_` | Subfolder install |

## Simple History Tables

The main Simple History tables (using `wp_` prefix):

- `wp_simple_history` - Main events table
- `wp_simple_history_contexts` - Event context/metadata

## Instructions

1. Read credentials from `CLAUDE.local.md`
2. Ask the user what SQL query they want to run (if not specified)
3. Run the query using the command pattern above
4. Display the results
5. Offer to run follow-up queries if needed

## Notes

- For complex queries, consider using `\G` at the end for vertical output
- Be careful with UPDATE/DELETE queries - always confirm with user first

Overview

This skill runs SQL queries against a WordPress development database inside the local Docker Compose environment. It helps inspect tables, read Simple History events, and debug WordPress data by executing mysql commands within the mariadb service. Use it to get quick, precise database answers without leaving the project directory.

How this skill works

The skill reads database connection details from CLAUDE.local.md, then constructs and runs a docker compose exec mariadb mysql command to execute the provided SQL. Results are captured and displayed; for large or complex results the skill can re-run queries using vertical output (\G) or refined SQL. It always confirms destructive statements (UPDATE/DELETE) before execution.

When to use it

  • Inspect WordPress tables and schemas
  • Query Simple History events or contexts
  • Count or sample records for debugging
  • Verify multisite or multi-install data across prefixes
  • Run ad-hoc SELECT/DESCRIBE queries during development

Best practices

  • Store and read credentials from CLAUDE.local.md; do not hard-code credentials in chat
  • Run commands from the docker-compose project directory so services are available
  • Use SELECT first to preview changes before any UPDATE/DELETE
  • Use LIMIT and ORDER BY for large tables to avoid huge dumps
  • Append \G for more readable vertical output on complex rows

Example use cases

  • Show all tables in a specific install: run SHOW TABLES; against the chosen database prefix
  • Inspect recent Simple History events: SELECT * FROM wp_simple_history ORDER BY id DESC LIMIT 10;
  • Describe a table structure: DESCRIBE wp_simple_history;
  • Count posts or other records: SELECT COUNT(*) FROM wp_posts;
  • Investigate multisite installs by querying tables with different prefixes like wp_multisite_ or wp_6_4_

FAQ

Where do I get the database credentials?

Credentials are stored in CLAUDE.local.md under Database Access; the skill reads them to build the docker mysql command.

Can I run UPDATE or DELETE queries?

Yes, but the skill will always ask for explicit confirmation before executing destructive statements to prevent accidental data loss.

What if a query returns too many rows?

Use LIMIT, add WHERE clauses, or re-run with \G for vertical output. The skill can help refine queries to reduce result size.