Tools [active]

MySQL Docker Manager

A Bash script that sets up MySQL 8.4 LTS with Docker Compose from scratch, then manages databases, users, SSL, and backups through an interactive menu.

Tech
Bash · Docker Compose · MySQL · OpenSSL
License
MIT
View on GitHub ↗

Problem

A database container is easy to start and easy to leave half-configured: no TLS, a shared superuser for every app, and backups that only exist as a plan. This script makes the safe setup the default and puts the day-to-day tasks behind one menu.

What it does

  • Sets up one MySQL instance (mysql:8.4) with Docker Compose: data and backup directories, .env, and compose.yaml.
  • TLS required for TCP connections (require_secure_transport=ON); root can only log in from inside the container.
  • Creates a database together with its own owner user, isolated from other databases.
  • Backs up with mysqldump to .sql.gz (validated), plus a backup of users and grants.
  • Restores from a list of available backups, locally or from Cloudflare R2.
  • Scheduled backups (systemd timer, or cron) with retention, stored locally, on R2, or both.
  • Password rotation, status, SSL checks, and logs.
  • Backup and restore of other MySQL servers (another VPS or a managed service) through connection profiles, even without a local instance.

Usage

All generated files stay in the folder that holds the script, so use one folder per instance:

sudo mkdir -p /opt/mysql
sudo cp mysql-manager.sh /opt/mysql/
sudo chmod +x /opt/mysql/mysql-manager.sh
sudo /opt/mysql/mysql-manager.sh

The first menu option runs the initial setup; the rest of the menu covers daily operations.

Notes

  • Docker Engine and the Compose plugin must already be installed; the script does not install them.
  • Runs as root (or with sudo).
  • R2 uploads use rclone in a container, so nothing extra needs to be installed on the host.