Railway

Deploy MySQL

Run MySQL 8 on Railway with Docker image and root password env.

Deploy MySQL

Just deployed

MySQL for railway.app

Template Header

Deploy MySQL 8 on Railway with the official Docker image. This template gives you a ready-to-run relational database for application data, background jobs, or as a shared backing store for other services in your project. It ships with sane defaults, a built-in health check, and guidance for attaching persistent storage so your data survives redeploys.

Deploy on Railway

πŸ—οΈ Architecture

flowchart LR
    Client(["πŸ“¦ App / Client"]) -->|"MySQL Protocol"| Proxy["Railway TCP Proxy"]
    Proxy -->|"$PORT β†’ 3306"| App["Container\nmysql:8.4"]
    App --> Volume[("Volume\n/var/lib/mysql")]

Environment

VariableRequiredDescription
MYSQL_ROOT_PASSWORDYesRoot password for MySQL

> [!IMPORTANT] > Set MYSQL_ROOT_PASSWORD (as a generated secret) in the Railway dashboard before the first deploy. On an uninitialized database, the container fails fast with a message pointing back here rather than starting without a password.

Optional

VariableDescription
MYSQL_DATABASEInitial database name (default app)
MYSQL_INIT_DUMP_URLHTTPS URL to a .sql or gzip-compressed .sql.gz dump; downloaded and imported automatically, but only on the first start of an empty volume. Takes precedence over MYSQL_INIT_DUMP_BASE64 if both are set.
MYSQL_INIT_DUMP_BASE64Same dump, base64-encoded and pasted directly as the variable value. Ignored if MYSQL_INIT_DUMP_URL is also set. Best for small dumps only.

> [!NOTE] > MYSQL_INIT_DUMP_URL/MYSQL_INIT_DUMP_BASE64 are only ever consulted on the very first start against a brand-new, empty volume. Once the database has initialized, both variables are silently ignored on every later restart or redeploy β€” even if you leave them set. The dump runs with full administrative privileges during bootstrap, so only point these at dumps from sources you trust.

Persistence

railway.toml declares requiredMountPath = "/var/lib/mysql". Attach a Railway volume to that path before production traffic β€” Railway will prompt for it based on this setting, but it is not created automatically.

Local

docker build -t railwayapp-mysql .
docker run --rm -e MYSQL_ROOT_PASSWORD=dev -p 3306:3306 railwayapp-mysql

Airbyte Apache Airflow CloudBeaver CodiMD Django Email Service FastAPI Flask Flowise GitLab CE Grafana Home Assistant InfluxDB MJML MongoDB Mosquitto MQTT MySQL n8n Node.js Node-RED OpenSearch Open WebUI Outerbase Studio PostgreSQL Redis TYPO3 CMS


Template Content

More templates in this category

View Template
Rocky Linux
[Jul'26] Hosted Rocky Linux 9 workspace with SSH and persistent storage. πŸš€

codestorm
40
View Template
Foundry Virtual Tabletop
A Self-Hosted & Modern Roleplaying Platform

Lucas
71
View Template
Letta Code Remote
Run a Letta Code agent 24/7. No inbound ports, just deploy.

Letta
51