Use when you need to analyze and solve MySQL performance or query design problems directly from a real codebase or database environment. Inspects SQL queries, table structure, index usage, and uses terminal tools (mysql, EXPLAIN) when possible. For pragmatic diagnosis of slow queries, joins, indexes, and filtering in existing applications.
Use this skill when you need to analyze and solve MySQL performance or query design problems directly from a real codebase or database environment. The skill is designed for practical investigation, not theoretical advice. It should inspect SQL queries, review table structure, evaluate index usage, and use available terminal tools such as mysql and EXPLAIN whenever possible.
This skill is intended for situations where the model should behave like a pragmatic senior engineer who is diagnosing slow queries, suspicious joins, missing indexes, or poor filtering strategies inside an existing application.
Use this skill when the task involves any of the following:
EXPLAIN on a query through terminal toolsThis skill should be preferred when the problem is tied to real MySQL behavior, not only static code style.
Do not use this skill when:
If the environment does not allow database access, the skill should still perform a static review, but it must clearly say that conclusions are limited because EXPLAIN, schema inspection, and real index verification were not executed.
This skill can work with one or more of the following inputs:
EXPLAIN, SHOW CREATE TABLE, or DESCRIBEThe skill should not block on perfect input. It should inspect whatever is available and continue.
The skill must try to achieve these goals in order:
EXPLAIN using terminal tools if possible.Follow this workflow in order. Do not jump straight to adding indexes without inspection.
First determine exactly what query is being executed.
Look for:
orderBy, groupBy, distinct, having, limit, and pagination patternsIf the input is Laravel code, reconstruct the effective SQL as faithfully as possible.
If terminal or DB access is available, inspect the relevant tables before proposing changes.
Prefer commands such as:
SHOW CREATE TABLE table_name;
DESCRIBE table_name;
SHOW INDEX FROM table_name;
If the codebase contains migrations, read them too, because the schema in code may reveal intent or upcoming changes.
If MySQL access is available, run EXPLAIN on the real query. Use terminal tools whenever possible.
Examples:
mysql -e "EXPLAIN SELECT ..."
mysql -e "EXPLAIN FORMAT=TRADITIONAL SELECT ..."
mysql -e "EXPLAIN FORMAT=JSON SELECT ..."
If the environment supports it and the query is a SELECT, prefer richer output when useful.
The skill should inspect at least these parts of EXPLAIN output:
Treat these as diagnostic signals, not absolute truth.
Check whether the query actually benefits from existing indexes.
Review especially:
WHEREORDER BYGROUP BYThe skill must distinguish between:
The skill should actively look for these issues:
LIKE '%term%'OR conditions that degrade index usageSELECT * on wide tables when fewer columns are neededOnly after inspection should the skill propose improvements.
Possible outputs include:
Every recommendation should include a reason.
When suggesting indexes, follow these rules:
End with a practical report that includes:
EXPLAIN summary if executedUse this response structure:
## MySQL Analysis Report
### Query under review
...
### Tables inspected
...
### Existing indexes
...
### EXPLAIN summary
...
### Problems found
- ...
### Recommended optimizations
1. ...
2. ...
### Suggested SQL or code rewrite
...
### Suggested index changes
...
### Risks and trade-offs
...
### Confidence / limitations
...
If terminal access or DB credentials are unavailable, explicitly say that EXPLAIN and live schema verification could not be performed.
The skill must behave according to these rules:
EXPLAIN whenever database access is possible.When terminal access is available, the skill should try to discover how to connect safely to MySQL by checking:
.envconfig/database.phpPossible command patterns:
cat .env | grep DB_
php artisan env
php artisan tinker
mysql --version
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" -e "SHOW TABLES;"
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" -e "SHOW CREATE TABLE users\G"
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" -e "EXPLAIN SELECT ..."
If credentials are unavailable or access fails, continue with static analysis and state that runtime verification could not be completed.
When the input is Laravel code, also inspect:
with()whereHas() and nested relationship filterswithCount() usagechunk() vs cursor() vs paginationIf useful, the skill may provide both:
@.cursor/skills/mysql-problem-solver analyze this query and check whether indexes are used effectively
@.cursor/skills/mysql-problem-solver inspect OrderRepository and use EXPLAIN if terminal access is available
@.cursor/skills/mysql-problem-solver review this slow MySQL query, inspect table structure, and propose safe index changes
@.cursor/skills/mysql-problem-solver analyze the Laravel query in this service, reconstruct the SQL, inspect indexes, and optimize it
A good result from this skill should:
EXPLAIN through available terminal toolsAfter completing the tasks