---
title: "Deploy MariaDB"
description: "Fast, reliable MySQL-compatible relational database."
category: "Storage"
url: https://railway.com/deploy/mariadb-sql
---

# Deploy MariaDB

Fast, reliable MySQL-compatible relational database.

**[Deploy MariaDB on Railway](https://railway.com/template/mariadb-sql)**

- **Creator:** INF Labs
- **Category:** Storage

## Template content

### mariadb https://cdn.svgporn.com/logos/mariadb-icon.svg

- **Image:** mariadb:lts

## Documentation

# Deploy and Host MariaDB on Railway

MariaDB is an open-source relational database designed as a MySQL-compatible database server for web applications, APIs, CMS platforms, analytics workloads, and general-purpose transactional systems. It provides SQL, transactions, indexing, replication capabilities, and broad compatibility with tools and applications built for the MySQL ecosystem.

## About Hosting MariaDB

Hosting MariaDB on Railway gives you a persistent relational database without manually managing a virtual machine, operating system, database package installation, or server lifecycle.

This template runs the official MariaDB Docker image and stores database files in a persistent Railway volume. Applications inside the same Railway project can connect through Railway private networking on port `3306`, while external database clients can connect through Railway TCP Proxy.

The deployment creates a root administrator account, a default application database, and a dedicated application user so applications do not need to connect using the root account.

## Common Use Cases

* Backend databases for web applications and APIs
* WordPress and other MySQL-compatible CMS platforms
* Transactional application data
* Internal business applications
* E-commerce and SaaS backends
* Development and testing environments
* Applications migrating from or compatible with MySQL

## Dependencies for MariaDB Hosting

* Official `mariadb:lts` Docker image
* Persistent Railway volume mounted at `/var/lib/mysql`

### Implementation Details

MariaDB stores its persistent database files at:

```text
/var/lib/mysql
```

A Railway volume is mounted at this location so databases, tables, indexes, users, and other database state remain available across container restarts and redeployments.

The database server communicates using the MySQL/MariaDB wire protocol on:

```text
TCP 3306
```

MariaDB is not an HTTP service, so external access should use Railway TCP Proxy rather than a standard HTTP public domain.

## Database Users

This template initializes two credential levels:

* **Root user** — intended for database administration
* **Application user** — intended for normal application connections

Applications should normally use the dedicated application user rather than connecting as `root`.

This helps keep administrative privileges separate from day-to-day application access.

## Database Connection

### Applications Inside Railway

Services running inside the same Railway project should use Railway private networking.

The private connection uses:

```text
:3306
```

A private connection URL can be referenced directly from the MariaDB service variables.

Using private networking keeps database traffic inside the Railway project and avoids exposing the database unnecessarily to the public internet.

### External Database Clients

For tools running outside Railway, such as:

* DBeaver
* HeidiSQL
* MySQL Workbench
* TablePlus
* command-line MySQL/MariaDB clients

use the Railway TCP Proxy hostname and port shown in the MariaDB service settings.

The TCP Proxy provides an externally reachable hostname and dynamically assigned port that forwards connections to MariaDB port `3306`.

## Connecting with a MariaDB Client

A typical connection uses:

```text
Host: 
Port: 
Database: app
Username: mariadb
Password: 
```

You can also use the generated connection URL exposed by the Railway service.

Example connection URI structure:

```text
mysql://mariadb:PASSWORD@HOST:PORT/app
```

## Test the Database

After connecting, verify the MariaDB server version:

```sql
SELECT VERSION();
```

Check the active database:

```sql
SELECT DATABASE();
```

Create a simple table:

```sql
CREATE TABLE users (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```

Insert a record:

```sql
INSERT INTO users (name, email)
VALUES ('Example User', 'user@example.com');
```

Query the table:

```sql
SELECT *
FROM users;
```

## MariaDB vs Similar Relational Databases

| Feature                       | MariaDB | MySQL | PostgreSQL | SQLite |
| ----------------------------- | :-----: | :---: | :--------: | :----: |
| Open source                   |    ✅    |   ✅   |      ✅     |    ✅   |
| MySQL protocol compatibility  |    ✅    |   ✅   |      ❌     |    ❌   |
| SQL relational database       |    ✅    |   ✅   |      ✅     |    ✅   |
| Multi-user server             |    ✅    |   ✅   |      ✅     |    ❌   |
| Persistent network database   |    ✅    |   ✅   |      ✅     |    ❌   |
| Transactions                  |    ✅    |   ✅   |      ✅     |    ✅   |
| Replication support           |    ✅    |   ✅   |      ✅     |    ❌   |
| Suitable for CMS platforms    |    ✅    |   ✅   |      ✅     |    ❌   |
| Single-file embedded database |    ❌    |   ❌   |      ❌     |    ✅   |

MariaDB is particularly useful when you need a familiar MySQL-compatible relational database while preferring an open-source database server with broad ecosystem compatibility.

Applications already designed for MySQL can often connect to MariaDB with little or no modification, although compatibility should still be verified for features that depend on a specific database version or MySQL-specific behavior.

## Getting Started After Deployment

1. Deploy the MariaDB template.
2. Wait for the database service to become available.
3. Retrieve the application username, password, and database name from the service variables.
4. For applications inside Railway, use the private database connection URL.
5. For applications outside Railway, enable or use the Railway TCP Proxy.
6. Connect using DBeaver, HeidiSQL, MySQL Workbench, a MariaDB client, or your application.
7. Run:

```sql
SELECT VERSION();
```

8. Create your application tables and begin using the database.

## 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 are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Garage S3 Storage](https://railway.com/deploy/garage-s3-storage) — Ultra-light S3 server: fast, open-source, plug-and-play.
- [Redis](https://railway.com/deploy/redis-1) — Self Host Latest Redis with Railway
- [EasyImg](https://railway.com/deploy/easyimg) — Simple self-hostable Nuxt.js personal image hosting system.

Open this page in a browser: https://railway.com/deploy/mariadb-sql
