Skip to content

catrenelle/MySQL-DBA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MySQL-DBA Skill for Claude Code

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

Fully compatible with MySQL 5.7/8.x and MariaDB 10.x/11.x, including cross-flavor backup and restore (a MySQL dump restores onto MariaDB and vice versa, with incompatible statements rewritten automatically).

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 connection details via environment variables (MARIADB_* names work as aliases):

Variable Description Default
MYSQL_HOST Server hostname localhost
MYSQL_PORT Server port 3306
MYSQL_USER Username (required)
MYSQL_PASSWORD Password (empty string = passwordless account) (required)
MYSQL_DATABASE Default database (optional)
MYSQL_ALLOW_CLEARTEXT Set to 1 to permit cleartext auth (PAM/LDAP) (off)

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 (reports server flavor + version)
  • server-info - Show detected flavor (mysql/mariadb) and version

Backup & Restore

  • dump <database> [--compat mysql|mariadb] - Full database dump (schema + data)
  • dump-schema <database> [--compat mysql|mariadb] - Schema only dump
  • import <file.sql[.gz]> [--force] [--no-rewrite] - Restore a dump file (alias: restore)

import accepts plain and gzipped dumps (its own, mysqldump/mariadb-dump, AutoMySQLBackup .sql.gz). It detects the target server's flavor and automatically rewrites statements that don't run there (MySQL 8 utf8mb4_0900_* collations, /*!80xxx */ version-gated comments, GTID_PURGED sets, MariaDB PAGE_CHECKSUM/Aria options), and strips DEFINER clauses that require SUPER to restore. Data statements are never modified.

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

# Restore it (works across MySQL <-> MariaDB)
node skills/mysql-dba/scripts/mysql-client.mjs import backup.sql

How It Works

This skill implements the MySQL client/server protocol (shared by MariaDB) from scratch:

  • Packet framing: 4-byte header (3-byte length + 1-byte sequence ID), with splitting at the 16MB protocol limit
  • Authentication: mysql_native_password and caching_sha2_password (MySQL 8 default), with AuthSwitchRequest and RSA full-auth handling
  • MariaDB detection: unmasks the 5.5.5- version prefix and adapts dumps/imports to the server flavor
  • Commands: COM_QUERY, COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_PING, etc.
  • Result parsing: Column definitions, row data, OK/ERR/EOF packets
  • Restore: dump-file statement splitting (strings, comments, DELIMITER) with automatic cross-flavor rewriting

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
  • Supports mysql_native_password and caching_sha2_password authentication; cleartext auth requires explicit opt-in (MYSQL_ALLOW_CLEARTEXT=1)
  • 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

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors