MySQL Connector
The MySQL connector enables AxonFlow agents to execute SQL queries and commands against MySQL and MariaDB databases with connection pooling, prepared statements, and policy enforcement.
Overview
| Property | Value |
|---|---|
| Type | mysql |
| Edition | Community |
| Auth Methods | DSN, Username/Password |
| Capabilities | query, execute, transactions, prepared_statements, connection_pooling, last_insert_id |
Use Cases
- Execute SQL queries for RAG context retrieval
- Store and retrieve application data with governance
- Access legacy MySQL databases in agent workflows
- Audit logging and compliance data management
Configuration
Environment Variables
# Option 1: Full DSN
MCP_mysql_CONNECTION_URL="user:password@tcp(host:3306)/database?parseTime=true"
# Option 2: Build from components
MCP_mysql_HOST="localhost"
MCP_mysql_PORT="3306"
MCP_mysql_DATABASE="mydb"
MCP_mysql_USER="myuser"
MCP_mysql_PASSWORD="mypassword"
# Optional - Connection Pool
MCP_mysql_MAX_OPEN_CONNS="25"
MCP_mysql_MAX_IDLE_CONNS="5"
MCP_mysql_CONN_MAX_LIFETIME="5m"
MCP_mysql_CONN_MAX_IDLE_TIME="5m"
# Optional - TLS
MCP_mysql_TLS="true" # or "skip-verify", "preferred"
# Optional - Tenant isolation
MCP_mysql_TENANT_ID="*"
DSN Format
[user]:[password]@tcp([host]:[port])/[database]?[parameters]
Common Parameters:
parseTime=true- Parse TIME/DATE/DATETIME to Go time.Time (recommended)loc=UTC- Timezone for parsed timescharset=utf8mb4- Character set (recommended for full UTF-8)timeout=10s- Connection timeoutreadTimeout=30s- Read timeoutwriteTimeout=30s- Write timeouttls=true- Enable TLS
Connector Config (Customer Portal)
{
"name": "app-mysql",
"type": "mysql",
"options": {
"host": "mysql.example.com",
"port": 3306,
"database": "appdb",
"tls": "true",
"max_open_conns": 25,
"max_idle_conns": 5,
"conn_max_lifetime": "5m"
},
"credentials": {
"username": "app_user",
"password": "secure_password"
}
}
Operations
Query Operations
Execute SELECT statements with named or positional parameters:
# Using named parameters (:name)
curl -X POST https://your-axonflow.com/mcp/resources/query \
-H "Content-Type: application/json" \
-d '{
"connector": "app-mysql",
"statement": "SELECT id, name, email FROM users WHERE status = :status AND created_at > :date",
"parameters": {
"status": "active",
"date": "2025-01-01"
}
}'
# Using positional parameters (?)
curl -X POST https://your-axonflow.com/mcp/resources/query \
-d '{
"connector": "app-mysql",
"statement": "SELECT * FROM products WHERE category = ? AND price < ?",
"parameters": {
"0": "electronics",
"1": 500.00
}
}'
Response:
{
"success": true,
"rows": [
{"id": 1, "name": "Alice", "email": "[email protected]"},
{"id": 2, "name": "Bob", "email": "[email protected]"}
],
"row_count": 2,
"duration_ms": 3.8,
"connector": "app-mysql"
}
Execute Operations
Run INSERT, UPDATE, DELETE statements:
# INSERT (returns last_insert_id)
curl -X POST https://your-axonflow.com/mcp/tools/execute \
-d '{
"connector": "app-mysql",
"action": "insert",
"statement": "INSERT INTO users (name, email, created_at) VALUES (:name, :email, NOW())",
"parameters": {
"name": "Charlie",
"email": "[email protected]"
}
}'
Response:
{
"success": true,
"rows_affected": 1,
"duration_ms": 2.1,
"message": "insert executed successfully (last_insert_id=42)",
"connector": "app-mysql"
}
Named vs Positional Parameters
The MySQL connector supports both parameter styles:
Named Parameters (:name)
{
"statement": "SELECT * FROM users WHERE name = :name AND status = :status",
"parameters": {
"name": "Alice",
"status": "active"
}
}
Positional Parameters (?)
{
"statement": "SELECT * FROM users WHERE name = ? AND status = ?",
"parameters": {
"0": "Alice",
"1": "active"
}
}
Named parameters are converted to ? placeholders internally for MySQL.
Connection Pooling
| Setting | Default | Description |
|---|---|---|
max_open_conns | 25 | Maximum open connections |
max_idle_conns | 5 | Maximum idle connections |
conn_max_lifetime | 5m | Maximum connection lifetime |
conn_max_idle_time | 5m | Maximum idle time before closing |
Health Check
curl https://your-axonflow.com/mcp/connectors/app-mysql/health
Response:
{
"healthy": true,
"latency_ms": 1.5,
"details": {
"open_connections": "5",
"in_use": "2",
"idle": "3",
"wait_count": "0",
"mysql_version": "8.0.35"
},
"timestamp": "2025-12-08T10:30:00Z"
}
Data Type Handling
The connector automatically converts MySQL types to appropriate Go/JSON types:
| MySQL Type | JSON Type |
|---|---|
| TINYINT, SMALLINT, INT, BIGINT | number |
| FLOAT, DOUBLE, DECIMAL | number (DECIMAL as string for precision) |
| VARCHAR, CHAR, TEXT | string |
| DATE, DATETIME, TIMESTAMP | string (ISO 8601) |
| JSON | object/array |
| BLOB, BINARY | base64 string |
| ENUM, SET | string |
| BOOLEAN | boolean |
Best Practices
Security
- Use TLS - Set
tls=truefor encrypted connections - Least privilege - Create users with minimal required permissions
- Named parameters - Prevents SQL injection
- Multi-statements disabled - Default setting blocks dangerous SQL
Performance
- Index your queries - Use EXPLAIN to verify index usage
- Connection pooling - Configure based on workload
- Query timeouts - Set readTimeout/writeTimeout appropriately
- Use LIMIT - Always limit result sets
Example User Setup
-- Read-only user
CREATE USER 'axonflow_reader'@'%' IDENTIFIED BY 'secure_password';
GRANT SELECT ON mydb.* TO 'axonflow_reader'@'%';
-- Read-write user
CREATE USER 'axonflow_writer'@'%' IDENTIFIED BY 'secure_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON mydb.* TO 'axonflow_writer'@'%';
-- Require SSL
ALTER USER 'axonflow_reader'@'%' REQUIRE SSL;
ALTER USER 'axonflow_writer'@'%' REQUIRE SSL;
FLUSH PRIVILEGES;
Troubleshooting
Connection Refused
- Verify host and port are correct
- Check MySQL is running and accepting remote connections
- Verify
bind-addressin MySQL config allows connections
Access Denied
- Verify username and password
- Check user has correct host permissions (
'user'@'host') - Ensure user has required grants on database
Unknown Database
- Verify database exists:
SHOW DATABASES; - Check user has access to database
TLS/SSL Issues
- For self-signed: Use
tls=skip-verify - For verified SSL: Configure CA certificate
- Check MySQL server has SSL enabled:
SHOW VARIABLES LIKE '%ssl%';
Character Encoding Issues
- Use
charset=utf8mb4in DSN - Ensure database and tables use utf8mb4
- Check collation matches application expectations