Deploy MySQL
Run MySQL 8 on Railway with Docker image and root password env.
railwayapp-mysql
Just deployed
MySQL for railway.app
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.
ποΈ 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
| Variable | Required | Description |
|---|---|---|
MYSQL_ROOT_PASSWORD | Yes | Root 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
| Variable | Description |
|---|---|
MYSQL_DATABASE | Initial database name (default app) |
MYSQL_INIT_DUMP_URL | HTTPS 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_BASE64 | Same 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
Template Content
railwayapp-mysql
vergissberlin/railwayapp-mysql