Creating a MySQL Database
To create a MySQL database in Dokploy:- Navigate to your project
- Select the environment
- Click “Add Service” and select “MySQL”
- Configure the database settings
Basic Configuration
- Name - A friendly name for your database
- App Name - The Docker service name (used for internal DNS)
- Description - Optional description
- Docker Image - Default:
mysql:latest(recommended:mysql:8.0ormysql:8.3)
Database Credentials
- Database Name - Name of the database to create
- Database User - Username for database access (can be
root) - Database Password - Password for the user
- Root Password - Password for the root user
These credentials are automatically configured via environment variables:
MYSQL_DATABASEMYSQL_USER(if user is not root)MYSQL_PASSWORD(if user is not root)MYSQL_ROOT_PASSWORD
Advanced Settings
- External Port - Optional port to expose MySQL externally (default internal port: 3306)
- Command - Override the default container command
- Args - Additional arguments to pass to MySQL
- Environment Variables - Additional custom environment variables
Connection Strings
Internal Connection (from other services)
When connecting from applications within the same Docker network:External Connection
If you’ve configured an external port (e.g., 3307):Connection String Formats
- Standard URI
- mysql Command
- Node.js (mysql2)
- Python (mysql-connector)
- PHP (mysqli)
Environment Variables
MySQL containers support these environment variables:| Variable | Description | Required |
|---|---|---|
MYSQL_ROOT_PASSWORD | Root user password | Yes |
MYSQL_DATABASE | Database to create on startup | Yes |
MYSQL_USER | User to create (if not root) | No |
MYSQL_PASSWORD | Password for MYSQL_USER | No |
MYSQL_ALLOW_EMPTY_PASSWORD | Allow root with empty password | No |
MYSQL_RANDOM_ROOT_PASSWORD | Generate random root password | No |
Data Persistence
MySQL data is stored in a Docker volume mounted at:- Mount Path:
/var/lib/mysql - Volume Name:
{appName}-data
Resource Configuration
Configure resource limits for your MySQL instance:Operations
Starting the Database
Click the “Start” button in the Dokploy UI or use the API:Stopping the Database
Click the “Stop” button or use the API:Reloading the Database
Reload applies configuration changes by stopping and starting the service:Rebuilding the Database
Accessing MySQL CLI
To access the MySQL CLI in the running container:Common MySQL Commands
Backups
Dokploy provides automated backup functionality for MySQL. Backups are performed usingmysqldump:
Troubleshooting
Connection Refused
- Verify the service is running in Dokploy UI
- Check the service name matches your
appName - Ensure your application is in the same Docker network
Authentication Failed
- Verify credentials in the database settings
- Check if using root requires
rootas username - For external connections, ensure user has
%host or specific IP
Character Encoding Issues
Set UTF-8 encoding in environment variables:Performance Issues
- Check slow query log
- Increase memory limits
- Optimize queries and add indexes
- Consider connection pooling
Best Practices
- Use Specific Versions - Pin to specific MySQL versions (e.g.,
mysql:8.0.35) instead oflatest - Strong Passwords - Use strong, randomly generated passwords for production
- Regular Backups - Configure automated backups and test restoration
- Monitor Resources - Watch memory and CPU usage, adjust limits as needed
- Connection Limits - Set appropriate
max_connectionsbased on your workload - Slow Query Log - Enable and monitor slow query log for optimization
- Security - Don’t expose MySQL externally unless necessary; use VPN or SSH tunnels
Performance Tuning
Add these environment variables or configuration options:MySQL vs MariaDB
Both MySQL and MariaDB are supported in Dokploy. Consider:- MySQL - Official Oracle version, better for compatibility
- MariaDB - Community fork, may have additional features
Next Steps
Backups
Configure automated MySQL backups
MariaDB
Learn about MariaDB as an alternative