DSN Format
MySQL connection strings use themysql:// protocol:
Basic Examples
Connection Options
SSL/TLS Modes
MySQL supports SSL configuration via thesslmode query parameter:
Timeouts
Configure connection and query timeouts via TOML:mysql2 library (src/connectors/mysql/index.ts:69-72, 136-138).
AWS RDS IAM Authentication
The connector automatically detects AWS IAM authentication tokens and configures the cleartext plugin:- Enables
mysql_clear_passwordauthentication plugin - Automatically enables SSL (required for IAM authentication)
- Sets
rejectUnauthorized: falsefor RDS certificates
Supported Features
Schemas (Databases)
In MySQL, “schema” and “database” are synonymous. List all databases:Tables and Views
Get tables in a database:DATABASE() function to get the current active database.
Table Schema with Comments
MySQL supports column comments:Indexes
MySQL indexes include:- Primary keys (
is_primary: true, index name isPRIMARY) - Unique indexes (
is_unique: true) - Multi-column indexes
- Full-text indexes
- Spatial indexes
Stored Procedures and Functions
MySQL supports both stored procedures and functions:SHOW CREATE PROCEDURE/SHOW CREATE FUNCTIONINFORMATION_SCHEMA.ROUTINES.ROUTINE_DEFINITIONINFORMATION_SCHEMA.ROUTINES.ROUTINE_BODY
Table Comments
Retrieve table-level comments:Query Execution
Parameterized Queries
MySQL uses? placeholders for parameters:
Multi-Statement Support
MySQL has native multi-statement support enabled by default:- SELECT results are aggregated into
rows - INSERT/UPDATE/DELETE counts are summed in
rowCount
Session Consistency
The connector uses dedicated connections from the pool for session consistency:Row Limiting
Applies database-native LIMIT clause for efficiency:Common Scenarios
Connect to Local MySQL
Connect to AWS RDS MySQL
Option 1: Standard AuthenticationConnect Through SSH Tunnel
Work with Multiple Databases
source_id parameter in MCP tools:
Cross-Database Queries
MySQL supports cross-database queries in a single connection:MySQL-Specific SQL Examples
JSON Queries
Window Functions (MySQL 8.0+)
CTEs (MySQL 8.0+)
Full-Text Search
Troubleshooting
Connection Refused
Error:connect ECONNREFUSED 127.0.0.1:3306
Solutions:
- Verify MySQL is running:
systemctl status mysql - Check bind-address in
/etc/mysql/mysql.conf.d/mysqld.cnf - Verify firewall rules:
sudo ufw status - Test with mysql client:
mysql -h localhost -u user -p
Authentication Failed
Error:Access denied for user 'username'@'host'
Solutions:
- Verify username and password
- Check user privileges:
- Grant access if needed:
SSL Connection Required
Error:Connections using insecure transport are prohibited
Solution: Add ?sslmode=require to your DSN:
Public Key Retrieval
Error:Client does not support authentication protocol requested by server
Solutions:
- Use mysql_native_password plugin:
- Or enable SSL with
sslmode=require
IAM Authentication Not Working
Error:Access denied with IAM token
Solutions:
- Verify IAM token is valid (expires in 15 minutes)
- Check database user is configured for IAM:
- Verify IAM policy allows
rds-db:connect - Ensure SSL is enabled (automatic with IAM tokens)
Database Not Selected
Error:No database selected
Solutions:
- Specify database in DSN:
mysql://user:pass@host:3306/mydb - Or use fully qualified table names:
database.table
Performance Tips
- Use connection pooling (enabled by default in connector)
- Enable query cache for read-heavy workloads (MySQL 5.7 and earlier)
- Use EXPLAIN to analyze query performance
- Create appropriate indexes for frequently queried columns
- Use prepared statements via parameterized queries to avoid SQL injection
- Optimize joins by ensuring join columns are indexed
- Use LIMIT for large result sets to reduce memory usage