Technology
The mysql module provides MySQL database integration for Project Forge applications. This module extends the base database module with MySQL-specific functionality, including driver integration, connection management, and MySQL-optimized features.
Overview
This module adds MySQL/MariaDB database support to Project Forge applications and requires the database module. It provides:
- Driver Integration: Official MySQL driver with connection pooling
- MySQL Features: Support for MySQL-specific SQL syntax and features
- Performance Optimization: Connection pooling and query optimization for MySQL
- Configuration: Environment-based configuration with sensible defaults
Key Features
MySQL Compatibility
- Support for MySQL 5.7+ and MariaDB 10.3+
- MySQL-specific SQL dialect handling
- Full UTF8MB4 character set support
- Native JSON data type support
Performance
- Optimized connection pooling for MySQL workloads
- Query plan caching and prepared statement support
- Connection health monitoring
- Configurable timeouts and limits
Security
- SSL/TLS encryption support
- Secure password handling
- Connection validation and health checks
- SQL injection protection through prepared statements
Configuration
Environment Variables
The module reads configuration from environment variables (with optional prefix):
db_host- MySQL server hostname (default:localhost)db_port- MySQL server port (default:3306)db_user- Username for database connectionsdb_password- Password for database connections (optional)db_database- Database name to connect todb_schema- Default schema to use (optional)db_max_connections- Maximum number of active and idle connectionsdb_debug- Enable SQL statement logging (true/false)
Usage
Basic Setup
1 | |
Custom Configuration
1 | |
With Environment Prefix
1 | |
MySQL-Specific Features
JSON Support
MySQL’s native JSON data type is fully supported:
1 | |
Character Set Handling
The module automatically configures UTF8MB4 for full Unicode support:
1 | |
Dependencies
This module requires:
database- Core database functionality- go-sql-driver/mysql - Official MySQL driver
- sqlx - Enhanced SQL operations
Production Considerations
Connection Pooling
- Set
db_max_connectionsbased on MySQL’smax_connectionssetting - Monitor connection usage with built-in telemetry
- Consider read/write splitting for high-traffic applications
Performance Tuning
- Enable query caching in MySQL configuration
- Use prepared statements for repeated queries
- Monitor slow query logs
Source Code
- Repository: https://github.com/kyleu/projectforge/tree/main/module/mysql
- License: CC0 (Public Domain)
- Author: Kyle U (kyle@kyleu.com)
See Also
- Database Module - Core database functionality
- PostgreSQL Module - PostgreSQL database support
- SQLite Module - Embedded database option
- Project Forge Documentation - Complete documentation