Skip to content

A Claude skill to grant it out of the box access to MySQL using TypeScript/JavaScript

License

Notifications You must be signed in to change notification settings

catrenelle/MySQL-DBA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MySQL-DBA Skill for Claude Code

A pure JavaScript MySQL protocol implementation for database administration tasks. No external MySQL client libraries required - it implements the MySQL wire protocol directly using only Node.js built-in modules.

Installation

Option 1: Install as a plugin from GitHub

/plugin marketplace add catrenelle/mysql-dba
/plugin install mysql-dba

Restart Claude Code after installation to load the plugin.

Option 2: Clone to your project

git clone https://github.com/catrenelle/MySQL-DBA .claude/plugins/mysql-dba

Option 3: Clone to personal plugins directory

git clone https://github.com/catrenelle/MySQL-DBA ~/.claude/plugins/mysql-dba

This makes the skill available across all your projects.

Usage

Once installed, invoke the skill in Claude Code:

/mysql-dba ping
/mysql-dba databases
/mysql-dba query "SELECT * FROM users LIMIT 10"

Or run the script directly:

node mysql-dba/scripts/mysql-client.mjs <command> [arguments]

Configuration

Set MySQL connection details via environment variables:

Variable Description Default
MYSQL_HOST Server hostname localhost
MYSQL_PORT Server port 3306
MYSQL_USER Username (required)
MYSQL_PASSWORD Password (required)
MYSQL_DATABASE Default database (optional)

If credentials are not set, the script will prompt interactively.

Commands

Query Operations

  • query <sql> - Execute SELECT, return JSON results
  • exec <sql> - Execute INSERT/UPDATE/DELETE, return affected rows

Schema Operations

  • databases - List all databases
  • tables [database] - List tables
  • describe <table> - Show table structure
  • create-db <name> - Create database
  • drop-db <name> - Drop database

User Administration

  • users - List all users
  • create-user <user> <host> <password> - Create user
  • drop-user <user> <host> - Drop user
  • grant <privileges> <database> <user> <host> - Grant privileges
  • revoke <privileges> <database> <user> <host> - Revoke privileges

Transaction Management

  • begin - Start transaction
  • commit - Commit transaction
  • rollback - Rollback transaction

Prepared Statements

  • prepare <sql> - Prepare statement (returns ID)
  • execute <id> [params...] - Execute with parameters
  • deallocate <id> - Deallocate statement

Server Status

  • status - Show server status
  • variables [pattern] - Show server variables
  • processlist - Show running processes
  • ping - Test connection

Backup

  • dump <database> - Full database dump (schema + data)
  • dump-schema <database> - Schema only dump

Output Format

All commands return JSON:

{
  "status": "ok",
  "data": [...],
  "rowCount": 10
}

Errors:

{
  "status": "error",
  "code": 1045,
  "message": "Access denied..."
}

Examples

# Test connection
node skills/mysql-dba/scripts/mysql-client.mjs ping

# List databases
node skills/mysql-dba/scripts/mysql-client.mjs databases

# Query with results
node skills/mysql-dba/scripts/mysql-client.mjs query "SELECT * FROM users WHERE active = 1"

# Create a user with privileges
node skills/mysql-dba/scripts/mysql-client.mjs create-user appuser localhost secretpass
node skills/mysql-dba/scripts/mysql-client.mjs grant "SELECT, INSERT, UPDATE" mydb appuser localhost

# Backup a database
node skills/mysql-dba/scripts/mysql-client.mjs dump myapp > backup.sql

How It Works

This skill implements the MySQL client/server protocol from scratch:

  • Packet framing: 4-byte header (3-byte length + 1-byte sequence ID)
  • Authentication: mysql_native_password (SHA1-based challenge-response)
  • Commands: COM_QUERY, COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_PING, etc.
  • Result parsing: Column definitions, row data, OK/ERR/EOF packets

No dependency on mysql, mysql2, or any native MySQL client libraries.

Requirements

  • Node.js 18+ (uses ES modules)
  • MySQL 5.7+ or MariaDB 10.2+

Security Notes

  • Store credentials in environment variables, never in code
  • Use MYSQL_PASSWORD env var for automation
  • The implementation supports mysql_native_password authentication
  • Consider using read-only users for query-only operations

License

MIT

About

A Claude skill to grant it out of the box access to MySQL using TypeScript/JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published