Deploy MariaDB — Open Source MySQL-Compatible Database
Self-host MariaDB — the open-source MySQL-compatible database
mariadb
Just deployed
/var/lib/mysql
Deploy and Host MariaDB on Railway
MariaDB is the open-source relational database created by MySQL's original developers — a high-performance, drop-in MySQL replacement that powers Wikipedia, WordPress.com, and countless production applications. This template provisions the official MariaDB image with auto-generated credentials, a persistent volume, and a private connection URL ready to use immediately, so your app has a MySQL-compatible database on your own infrastructure in minutes — without exposing it to the internet.
What This Template Deploys
| Service | Purpose |
|---|---|
| MariaDB | The relational database server on port 3306 |
A single service with a persistent volume mounted at /var/lib/mysql, so your data survives redeploys. Root and application credentials are generated automatically, and the database is reachable over Railway's private network — port 3306 is never exposed publicly by default.
About Hosting
MariaDB is straightforward to run, but a couple of specifics keep your data safe and your app connected — both handled here.
The volume at /var/lib/mysql is your entire database — persist it. MariaDB writes all data to /var/lib/mysql. Without a mounted volume, everything is lost when the container restarts or redeploys. This template mounts a persistent volume there, so your databases, tables, and rows survive deployments. On Railway's volumes, the template also handles the lost+found directory that can otherwise interfere with first-time initialization, so the database initializes cleanly.
Connect over the private network — don't expose 3306. Your application should connect using the private connection URL over Railway's internal network, keeping port 3306 off the public internet. This is faster (internal traffic is free and low-latency) and far safer than a publicly reachable database. Expose a public endpoint only if you specifically need external access.
Credentials are auto-generated on first deploy. The root password and an application user and password are created as cryptographically random values on first boot, via MARIADB_ROOT_PASSWORD, MARIADB_USER, MARIADB_PASSWORD, and MARIADB_DATABASE. Pull them from your Railway variables to connect. Note the MariaDB image uses MARIADB_-prefixed variables (not MYSQL_), a common source of confusion when adapting other guides.
It's a MySQL-compatible drop-in. MariaDB speaks the MySQL protocol and works with MySQL clients, ORMs, and tooling, so applications expecting MySQL connect without changes. Choose MariaDB for a fully open-source, community-driven database with no Oracle dependency; choose MySQL only if you need MySQL 8.0-specific features or Oracle support contracts.
Back up and upgrade deliberately. Because all state lives on the volume, regular backups (mysqldump or volume snapshots) protect your data. When upgrading major versions, follow MariaDB's upgrade path rather than swapping images blindly, since schema compatibility needs the proper upgrade step.
Typical cost: ~$5/month on Railway for the service plus volume storage, scaling with your data size. MariaDB Community Server is free and open source under the GPL — you pay only for infrastructure.
How It Compares
| MariaDB (self-hosted) | MySQL | PostgreSQL | Managed cloud DB | |
|---|---|---|---|---|
| License | Fully open (GPL) | Open + Oracle | Open | Vendor |
| MySQL compatibility | Drop-in | Native | No | Varies |
| Oracle dependency | None | Yes | None | N/A |
| Cost model | Flat infra | Flat infra | Flat infra | Per instance/hour |
| Data ownership | Full — your infra | Full | Full | Vendor |
| Self-hostable | Yes | Yes | Yes | No |
MySQL is closely related but Oracle-stewarded; MariaDB is its fully community-driven fork with no Oracle dependency. PostgreSQL is excellent but a different engine and dialect — not a drop-in for MySQL apps. Managed cloud databases remove ops work but bill per instance-hour and hold your data. MariaDB's edge is being the open, MySQL-compatible choice you can drop into any MySQL-expecting app — self-hosted, at flat cost, with your data on infrastructure you own.
Deploy in Under 5 Minutes
- Click Deploy on Railway — MariaDB builds with a volume and generated credentials (~2 minutes)
- Confirm the volume is mounted at
/var/lib/mysql - Copy the private connection URL and credentials from your Railway variables
- Point your application at the private URL over Railway's internal network
- Create your schema and start querying — your data persists across redeploys
Keep port 3306 private unless you specifically need external access.
Common Use Cases
- Database for a MySQL app — a drop-in MySQL-compatible backend for any app or framework expecting MySQL
- WordPress and PHP stacks — the database behind WordPress, Laravel, and other PHP applications
- Web application backend — persistent relational storage for your app deployed alongside it on Railway
- Legacy app hosting — run applications built for MySQL without rewriting their data layer
- Self-hosted data ownership — keep your relational data on your own infrastructure, not a vendor's
Configuration
| Variable | Required | Description |
|---|---|---|
MARIADB_ROOT_PASSWORD | Auto-generated | Root password — created randomly on first deploy |
MARIADB_DATABASE | Auto-set | Initial database created on first boot |
MARIADB_USER | Auto-generated | Application user with access to the database |
MARIADB_PASSWORD | Auto-generated | Application user password |
MARIADB_PRIVATE_URL | Provided | Private connection URL for your app (internal network) |
| Storage volume | Pre-set | Persistent volume at /var/lib/mysql for all data |
Persist the volume, and connect privately. All data lives at
/var/lib/mysql— without the volume, a redeploy wipes it. Connect your app via the private URL over Railway's network rather than exposing port3306publicly.
Use
MARIADB_-prefixed variables. The official MariaDB image expectsMARIADB_ROOT_PASSWORDand related variables, not theMYSQL_names some guides use — a frequent cause of a container that won't start.
Dependencies for MariaDB Hosting
- Railway account — ~$5/month plus volume storage, scaling with data size
- A persistent Railway volume at
/var/lib/mysql(included) - An application or client that speaks the MySQL protocol
- Optional: a GUI like pgAdmin's MySQL equivalent, DBeaver, or TablePlus to browse data
Deployment Dependencies
- MariaDB Official Site
- MariaDB Documentation
- Official MariaDB Docker Image
- Railway Volumes Documentation
Implementation Details
The template runs the official mariadb image on port 3306 with a persistent volume at /var/lib/mysql, so all databases and tables survive redeploys. On first boot, MariaDB initializes with cryptographically random credentials set through MARIADB_ROOT_PASSWORD, MARIADB_USER, MARIADB_PASSWORD, and MARIADB_DATABASE; the template also accounts for the lost+found directory Railway's ext4 volumes place at the mount root, which can otherwise block first-time initialization.
Connectivity is designed around the private network: applications connect via the private URL without exposing port 3306, which is faster and more secure than a public endpoint. MariaDB is a drop-in replacement for MySQL, speaking the same protocol and compatible with MySQL clients, ORMs, and tooling. All state resides on the volume, which is the component to back up with mysqldump or volume snapshots. Major-version upgrades should follow MariaDB's documented upgrade process to preserve schema compatibility rather than swapping images directly.
Frequently Asked Questions
Does my data persist across redeploys? Yes — all data lives on the volume mounted at /var/lib/mysql, which survives redeploys. Without a mounted volume, MariaDB data is lost on restart, so the volume is essential.
How do I connect my app? Use the private connection URL from your Railway variables over the internal network, with the auto-generated user and password. Keep port 3306 off the public internet unless you specifically need external access.
Is MariaDB compatible with MySQL? Yes — it's a drop-in replacement built by MySQL's original developers, speaking the same protocol and compatible with MySQL clients, ORMs, and frameworks. Most MySQL apps work without changes.
Why won't my container start with MYSQL_ variables? The official MariaDB image uses MARIADB_-prefixed variables. Using MYSQL_ names from a MySQL guide is a common reason the container fails to initialize — this template uses the correct ones.
How do I back up my database? Use mysqldump for logical backups or Railway volume snapshots for full-data backups. Since everything lives on the volume, regular backups protect against loss.
Should I expose port 3306 publicly? Generally no. Connect over Railway's private network for speed and security. Only expose a public endpoint if you need external access, and protect it.
Why Deploy MariaDB on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying MariaDB on Railway you get an open-source, MySQL-compatible database with the essentials handled — a persistent volume so your data survives redeploys, auto-generated credentials, private networking so it isn't exposed, and clean initialization. Drop-in MySQL compatibility for your apps, self-hosted on infrastructure you own.
Template Content
mariadb
mariadb:latest