# Self-host MySQL

> The MySQL Community database server on the official image, with a persistent volume, generated root and user passwords, and an application database. It is not published on the host, so reach it from other services in this project at mysql:3306.

- Page: https://levelrail.com/templates/mysql/
- JSON: https://levelrail.com/templates/mysql.json
- Category: Database Tools
- Licence: GPL-2.0-only (Copyleft license)
- Source: https://github.com/mysql/mysql-server
- Upstream docs: https://dev.mysql.com/doc/refman/8.4/en/

## Requirements
- Memory: about 768 MiB
- amd64: unknown, arm64: unknown
- Needs configuration before start: no
- Pinned image tag: 8.4.13

## Services

| Service | Image | Tag | Ports | Volumes |
| --- | --- | --- | --- | --- |
| mysql | mysql | 8.4.13 | 3306 | mysql_data -> /var/lib/mysql |

## Environment

| Service | Variable | Kind |
| --- | --- | --- |
| mysql | MYSQL_DATABASE | preset |
| mysql | MYSQL_PASSWORD | generated |
| mysql | MYSQL_ROOT_PASSWORD | generated |
| mysql | MYSQL_USER | preset |

## Deploy

### CLI

```bash
levelrail-cli templates install mysql --name my-mysql
```

Add --domain SERVICE=HOST to serve a service on your own domain, for example --domain mysql=app.example.com.

### API

```bash
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://levelrail.example.com/api/v1/service-templates/mysql/install \
  -d '{
    "name": "my-mysql"
  }'
```

Create a token in the dashboard first. Name, env and domains are the request fields.

## First run
1. Read the generated passwords from the app secrets, then connect with the application user or as root from a service in the same project.

## Questions

### Can I deploy MySQL on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for MySQL, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image mysql:8.4.13 is what you deploy there.

Self-host MySQL, MySQL docker compose file, deploy MySQL on a VPS: this page lists the pinned image, ports, volumes and the commands for each.
