A real-time MySQL protocol query capture, analysis, and replay tool built with Go. Perfect for database performance testing, workload analysis, and debugging production query issues.
- Capture: Real-time network packet capture for MySQL queries
- Analyze: Comprehensive query analysis and reporting using DuckDB
- Replay: Accurate query replay for testing and benchmarking
- Cross-platform: Support for Linux, macOS (ARM64/AMD64), and Windows
- Go 1.25 or higher
- libpcap development libraries
- Root/Administrator privileges (required for packet capture)
macOS:
brew install libpcapUbuntu/Debian:
sudo apt-get install libpcap-devCentOS/RHEL:
sudo yum install libpcap-develmake buildCGO_ENABLED=1 go build -o cassette-tape main.goCapture queries from a specific network interface and port:
./cassette-tape capture --device lo0 --port 3306 --level infoOptions:
--device: Network interface (default: lo0)--port: MySQL port (default: 3306)--level: Log level - info or debug (default: info)
Example:
# Capture from loopback interface on port 3306
./cassette-tape capture --device lo0 --port 3306
# Capture with debug logging
./cassette-tape capture --device eth0 --port 3306 --level debugAnalyze the captured queries and generate reports:
./cassette-tape analyze --memoryOptions:
--memory: Enable DuckDB in-memory mode for faster processing
Replay captured queries against a target MySQL database:
./cassette-tape replay --host 127.0.0.1 --port 3306 --user root --password "" --db test --readonly --memoryOptions:
--host: Target MySQL host (default: 127.0.0.1)--port: Target MySQL port (default: 3306)--user: MySQL username (default: root)--password: MySQL password (default: "")--db: Target database name (default: test)--readonly: Only replay SELECT statements (default: true)--memory: Enable DuckDB in-memory mode (default: false)
Example:
# Replay queries to local MySQL in read-only mode
./cassette-tape replay --host localhost --user myuser --password mypass --db production --readonly
# Replay all query types (including INSERT/UPDATE/DELETE)
./cassette-tape replay --host 192.168.1.100 --user admin --password secret --db staging --readonly=falseWhen capturing queries, ensure your MySQL client has these settings:
# Disable prepared statements (required for parsing)
useServerPrepStmts=false
# Disable SSL (required for packet capture)
--ssl-mode=disabled
useSSL=false- Root/Admin Required: Packet capture requires elevated privileges
- Network Interface: Must capture from the correct network interface
- Port Filtering: Only captures traffic on the specified port
- TCP Only: Currently supports only TCP connections
- Prepare/Execute: Cannot parse prepared statement prepare/execute pairs
- SSL/TLS: Encrypted connections cannot be captured
- Compression: Compressed connections may not be fully parsed
- Read-only Mode: Default mode only replays SELECT statements
- Transaction Handling: Complex transactions may not replay correctly
cassette-tape/
βββ analyze/ # Query analysis and reporting
βββ capture/ # Network packet capture
βββ db/ # Database connections (MySQL, DuckDB)
βββ option/ # Configuration options
βββ replay/ # Query replay engine
βββ main.go # CLI application entry point
# Build and run
make dev
# Clean build artifacts
make clean
# Show available commands
make helpThe capture command generates a JSON file with the following naming pattern:
Queries_YYYY-MM-DDTHH:MM:SS.json
This file contains all captured queries with metadata including:
- Source IP and port
- Query text
- Timestamp
- Connection information
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Use
--memoryflag for faster DuckDB operations - Capture from loopback interface (lo0) for local testing
- Set appropriate log levels to reduce overhead
- Consider using dedicated network interfaces for production capture
Permission Denied:
sudo ./cassette-tape captureInterface Not Found:
# List available interfaces
ifconfig -a # macOS/Linux
ip addr # LinuxNo Queries Captured:
- Verify MySQL client settings (disable SSL, prepared statements)
- Check network interface and port configuration
- Ensure MySQL traffic is flowing through the specified interface
- Verify root/admin privileges
Build Errors:
- Ensure CGO is enabled:
CGO_ENABLED=1 - Install libpcap development libraries
- Use Go 1.25 or higher