Skip to content
Back to Deployment

Deploying MySQL

Self-hosted MySQL with Docker, replication, and tuning for production.

PlatformsAdvanced

Why

Self-hosted MySQL gives control over storage engine, replication topology, and config tuning. With Group Replication or InnoDB Cluster, you get HA with automatic failover.

Platform-as-a-Service adoption grew 24% in 2024 as teams shift from VM management to git-push deploys. the cloud infrastructure market reached $330B in 2024, growing 22% year-over-year (Synergy Research), and PaaS layers capture the majority of new workloads.

When

Use self-hosted MySQL for legacy apps, specific storage needs, and cost at scale. Prefer PlanetScale/RDS for managed.

How

1. Docker — mysql:8 image with volume 2. Config — my.cnf tuning (innodb_buffer_pool_size, max_connections) 3. Init — init.sql in docker-entrypoint-initdb.d 4. Backup — mysqldump or mysqlbackup (Enterprise) 5. Replication — source + replica, or Group Replication 6. HA — InnoDB Cluster with MySQL Router 7. Monitoring — performance_schema, slow query log

Example

# docker-compose.yml services: mysql: image: mysql:8 environment: MYSQL_ROOT_PASSWORD: secret MYSQL_DATABASE: mydb volumes: - mysqldata:/var/lib/mysql - ./my.cnf:/etc/mysql/conf.d/my.cnf command: --default-authentication-plugin=mysql_native_password volumes: mysqldata: # my.cnf [mysqld] innodb_buffer_pool_size = 1G max_connections = 200 slow_query_log = 1 long_query_time = 2 # Backup docker exec mydb mysqldump -u root -p mydb | gzip > backup.sql.gz

Common Problems

  • ⚠innodb_buffer_pool_size too low — default 128MB, set to 70% of RAM for dedicated DB
  • ⚠Authentication plugin error — MySQL 8 default caching_sha2, set native_password for old clients
  • ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical

Best Practices

  • ✓Set innodb_buffer_pool_size to 70% of RAM — biggest InnoDB performance win
  • ✓Use Group Replication for HA — automatic failover, multi-source
  • ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit

FAQ