Skip to main content
MySQL is the world’s most popular open-source relational database. Dokploy provides seamless deployment and management of MySQL instances as Docker services.

Creating a MySQL Database

To create a MySQL database in Dokploy:
  1. Navigate to your project
  2. Select the environment
  3. Click “Add Service” and select “MySQL”
  4. 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.0 or mysql: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_DATABASE
  • MYSQL_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:
Example:

External Connection

If you’ve configured an external port (e.g., 3307):
Example:

Connection String Formats

Environment Variables

MySQL containers support these environment variables: Dokploy automatically sets the required variables based on your configuration.

Data Persistence

MySQL data is stored in a Docker volume mounted at:
  • Mount Path: /var/lib/mysql
  • Volume Name: {appName}-data
The volume persists even when the container is stopped or removed.

Resource Configuration

Configure resource limits for your MySQL instance:
For production workloads, allocate at least 2GB of memory and 1 CPU core. MySQL can be memory-intensive with large datasets.

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

Rebuilding will delete all data. Make sure to backup first!

Accessing MySQL CLI

To access the MySQL CLI in the running container:
Or use the Dokploy terminal feature in the UI.

Common MySQL Commands

Backups

Dokploy provides automated backup functionality for MySQL. Backups are performed using mysqldump:
See the Backups page for detailed backup configuration.

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 root as username
  • For external connections, ensure user has % host or specific IP

Character Encoding Issues

Set UTF-8 encoding in environment variables:
Or use command args:

Performance Issues

  • Check slow query log
  • Increase memory limits
  • Optimize queries and add indexes
  • Consider connection pooling

Best Practices

  1. Use Specific Versions - Pin to specific MySQL versions (e.g., mysql:8.0.35) instead of latest
  2. Strong Passwords - Use strong, randomly generated passwords for production
  3. Regular Backups - Configure automated backups and test restoration
  4. Monitor Resources - Watch memory and CPU usage, adjust limits as needed
  5. Connection Limits - Set appropriate max_connections based on your workload
  6. Slow Query Log - Enable and monitor slow query log for optimization
  7. Security - Don’t expose MySQL externally unless necessary; use VPN or SSH tunnels

Performance Tuning

Add these environment variables or configuration options:
For MySQL 8.0+, many traditional optimizations are automatic. Focus on proper indexing and query optimization.

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
See the MariaDB documentation for MariaDB-specific information.

Next Steps

Backups

Configure automated MySQL backups

MariaDB

Learn about MariaDB as an alternative