Deploy MySQL
Run MySQL on Andasy as an application with a persistent volume and private network access.
MySQL is not a managed Andasy database engine. You deploy it as a regular application with a volume, then connect from other apps on the private network. For a managed relational database, use PostgreSQL.
Prerequisites
- An Andasy account
- The Andasy CLI
Log in:
andasy auth login
Create the application
Create the application:
andasy apps create
Use the same name in andasy.hcl and in later commands. Replace <app-name> with that name throughout this guide.
Clone the example:
git clone https://github.com/quarksgroup/andasy-mysql-example.git
cd andasy-mysql-example
Set app_name in andasy.hcl to <app-name>. Set image to the MySQL version you need (8.0, 5.7, 8.4, 9.0, or a pin such as 8.0.40).
Do not change major versions on an existing volume:
Pick the version before the first deploy. Changing major versions on the same mysql_data volume can fail. Use a new volume if you need another major version.
Set primary_region to kgl (Kigali) or fsn (Falkenstein, Germany). Use the same region as the application that will connect to this database. See Regions.
compute.memory starts at 512 MiB. That is a starting point, not a requirement.
app_name = "<app-name>"
app {
primary_region = "kgl"
image = "mysql:8.0"
env = {
MYSQL_DATABASE = "app"
}
compute {
cpu = 1
memory = 512
cpu_kind = "shared"
}
process {
name = "<app-name>"
}
storage {
name = "mysql_data"
destination = "/var/lib/mysql"
}
}
Create a volume
andasy volumes create -a <app-name> -s 1 mysql_data
The volume name must match storage.name. The mount point is /var/lib/mysql. Attach this volume only to the MySQL application. Your application does not mount it. See Persistent storage volumes.
Deploy, set secrets, restart
andasy secret set requires a release. Deploy once first:
andasy deploy
MySQL may not stay up yet. Logs may show that MYSQL_ROOT_PASSWORD is missing. Andasy may warn that https://<app-name>.andasy.dev is not available. That is expected: MySQL is not an HTTP service.
Then set credentials and restart:
andasy secret set MYSQL_ROOT_PASSWORD='your-root-password' MYSQL_USER=app MYSQL_PASSWORD='your-app-password' -a <app-name>
andasy apps restart -a <app-name>
andasy logs -a <app-name>
Wait until logs show ready for connections. MYSQL_DATABASE comes from andasy.hcl (default app). See Secrets.
Connect
MySQL listens on port 3306 inside the container. Do not use https://<app-name>.andasy.dev as the database host.
From your laptop
andasy proxy 3306:3306 -a <app-name>
In another terminal:
mysql -h 127.0.0.1 -P 3306 -u app -p
See Proxy.
From another Andasy application
Use the private hostname. That application does not attach mysql_data.
| Field | Value |
|---|---|
| Host | <app-name>.internal |
| Port | 3306 |
| Database | app (or your MYSQL_DATABASE) |
| User | app (or your MYSQL_USER) |
| Password | the secret you set |
mysql://app:PASSWORD@<app-name>.internal:3306/app
Replace <app-name> with your app_name. Both apps must be in the same organization and region. Store the password as a secret on the connecting application.
Import a dump
andasy proxy 3306:3306 -a <app-name>
mysql -h 127.0.0.1 -P 3306 -u app -p app < your-dump.sql
Related Documentation
A complete sample lives in andasy-mysql-example.