mysql
MySQL is the world's most popular open-source relational database management system. Learn installation, SQL queries, indexing strategies, replication setup, and client integration with Node.js (mysql2) and Python (mysql-connector).
What this skill does
# MySQL
MySQL is a robust relational database used from small apps to large-scale web platforms. It supports ACID transactions, replication, and extensive SQL features.
## Installation
```bash
# Docker (recommended for development)
docker run -d --name mysql -p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=myapp \
mysql:8
# Ubuntu/Debian
sudo apt-get install mysql-server
sudo mysql_secure_installation
# macOS
brew install mysql && brew services start mysql
# Node.js driver
npm install mysql2
# Python driver
pip install mysql-connector-python
```
## CLI Basics
```bash
# Connect to MySQL
mysql -u root -p
# Connect to specific database
mysql -u root -p myapp
# Execute query from command line
mysql -u root -p -e "SHOW DATABASES;"
# Import SQL file
mysql -u root -p myapp < schema.sql
# Export database
mysqldump -u root -p myapp > backup.sql
```
## Schema Design
```sql
-- schema.sql: Create tables with proper types, indexes, and constraints
CREATE DATABASE IF NOT EXISTS myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE myapp;
CREATE TABLE users (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_created (created_at)
) ENGINE=InnoDB;
CREATE TABLE orders (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,
total_cents INT UNSIGNED NOT NULL DEFAULT 0,
status ENUM('pending','paid','shipped','completed','cancelled') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
INDEX idx_user_status (user_id, status)
) ENGINE=InnoDB;
```
## Indexing Strategies
```sql
-- indexing.sql: Common indexing patterns for performance
-- Composite index for multi-column queries (leftmost prefix rule)
CREATE INDEX idx_orders_status_date ON orders(status, created_at);
-- Covering index — query answered entirely from index
CREATE INDEX idx_users_email_name ON users(email, name);
-- Full-text index for search
ALTER TABLE products ADD FULLTEXT INDEX ft_search (name, description);
SELECT * FROM products WHERE MATCH(name, description) AGAINST('laptop' IN BOOLEAN MODE);
-- Check query execution plan
EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 42 AND status = 'paid';
```
## Node.js with mysql2
```javascript
// db.js: MySQL connection pool with mysql2 and promise API
const mysql = require('mysql2/promise');
const pool = mysql.createPool({
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'root',
password: process.env.DB_PASS || 'secret',
database: 'myapp',
waitForConnections: true,
connectionLimit: 10,
charset: 'utf8mb4',
});
async function getUser(id) {
const [rows] = await pool.execute(
'SELECT id, email, name FROM users WHERE id = ?',
[id]
);
return rows[0] || null;
}
async function createOrder(userId, totalCents) {
const conn = await pool.getConnection();
try {
await conn.beginTransaction();
const [result] = await conn.execute(
'INSERT INTO orders (user_id, total_cents) VALUES (?, ?)',
[userId, totalCents]
);
await conn.commit();
return result.insertId;
} catch (err) {
await conn.rollback();
throw err;
} finally {
conn.release();
}
}
module.exports = { pool, getUser, createOrder };
```
## Python Client
```python
# db.py: MySQL connection with mysql-connector-python
import mysql.connector
from mysql.connector import pooling
pool = pooling.MySQLConnectionPool(
pool_name="myapp",
pool_size=5,
host="localhost",
user="root",
password="secret",
database="myapp",
charset="utf8mb4",
)
def get_user(user_id):
conn = pool.get_connection()
try:
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT id, email, name FROM users WHERE id = %s", (user_id,))
return cursor.fetchone()
finally:
conn.close()
def insert_users(users):
conn = pool.get_connection()
try:
cursor = conn.cursor()
cursor.executemany(
"INSERT INTO users (email, name, password_hash) VALUES (%s, %s, %s)",
users,
)
conn.commit()
finally:
conn.close()
```
## Replication Setup
```ini
# my.cnf (primary): Enable binary logging for replication
[mysqld]
server-id = 1
log-bin = mysql-bin
binlog-format = ROW
gtid-mode = ON
enforce-gtid-consistency = ON
```
```sql
-- replication.sql: Configure replica to follow primary
-- On primary: create replication user
CREATE USER 'repl'@'%' IDENTIFIED BY 'repl_password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
-- On replica: start replication
CHANGE REPLICATION SOURCE TO
SOURCE_HOST='primary-host',
SOURCE_USER='repl',
SOURCE_PASSWORD='repl_password',
SOURCE_AUTO_POSITION=1;
START REPLICA;
SHOW REPLICA STATUS\G
```
## Backup and Maintenance
```bash
# backup.sh: Automated backup with compression
mysqldump -u root -p --single-transaction --routines --triggers myapp | gzip > "backup_$(date +%Y%m%d).sql.gz"
# Restore from backup
gunzip < backup_20260219.sql.gz | mysql -u root -p myapp
```
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.