Railway

Deploy MySQL Server

Production-ready MySQL with persistent storage and TCP access.

Deploy MySQL Server

Just deployed

/var/lib/mysql

Deploy and Host MySQL Server on Railway

MySQL is a widely used open-source relational database built for web applications, APIs, backend services, transactional systems, and general-purpose data storage. It provides SQL, ACID transactions, indexing, replication, stored procedures, JSON support, and broad compatibility across modern application frameworks and development tools.

About Hosting MySQL Server

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

This template runs MySQL as a dedicated database service with persistent Railway storage. Applications inside the same Railway project can connect through Railway private networking, while external database clients can connect through Railway TCP Proxy.

The deployment also creates a dedicated application database and user alongside the root administrator account, making it easier to separate normal application access from database administration.

Common Use Cases

  • Backend databases for web and mobile applications
  • API and microservice data storage
  • SaaS application databases
  • E-commerce and CMS platforms
  • Transactional business systems
  • Development and testing environments
  • Applications built with Laravel, Node.js, Django, Java, PHP, and other frameworks

Dependencies for MySQL Hosting

  • Official MySQL Docker image
  • Persistent Railway volume mounted at /var/lib/mysql
  • Railway private networking for internal connections
  • Optional Railway TCP Proxy for external access

Implementation Details

MySQL communicates using its native wire protocol on:

TCP 3306

Database files are stored persistently at:

/var/lib/mysql

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

MySQL Architecture on Railway

Application / Backend
        │
        │ Railway Private Network
        ▼
     MySQL :3306
        │
        ▼
 Railway Volume
 /var/lib/mysql

External tools connect through Railway TCP Proxy:

DBeaver / Workbench / CLI
          │
          │ TCP Proxy
          ▼
       MySQL :3306

MySQL is not an HTTP service, so a standard Railway public domain is not used for database connections.

Database Users

This template initializes two access levels:

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

Applications should normally use the dedicated application user instead of the root account.

This reduces unnecessary privilege exposure and makes access management cleaner.

Database Connection

Applications Inside Railway

Applications running inside the same Railway project should use the private database connection URL:

${{MySQL-Server.DATABASE_URL}}

This connection stays inside Railway private networking and uses the internal MySQL port 3306.

External Applications and Database Clients

For applications outside Railway, use:

${{MySQL-Server.DATABASE_PUBLIC_URL}}

This connection uses Railway TCP Proxy.

Compatible tools include:

  • MySQL Workbench
  • DBeaver
  • DataGrip
  • TablePlus
  • HeidiSQL
  • MySQL CLI
  • application drivers for Node.js, Python, Java, PHP, Go, and other languages

Connection Details

A typical MySQL connection contains:

Host
Port
Database
Username
Password

Internal Railway services connect directly on:

3306

External clients use the hostname and dynamically assigned port provided by Railway TCP Proxy.

Example URI structure:

mysql://USERNAME:PASSWORD@HOST:PORT/DATABASE

Testing MySQL

After connecting, verify the MySQL version:

SELECT VERSION();

Check the active database:

SELECT DATABASE();

Create a simple table:

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

Insert a record:

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

Query the table:

SELECT *
FROM users;

MySQL Features

CapabilityMySQL
Open-source relational database
SQL support
ACID transactions
JSON support
Secondary indexes
Full-text search
Views
Stored procedures
Triggers
Replication
Role and user management
Persistent Railway storage
Railway private networking
External TCP access

MySQL is particularly well suited to application workloads that require a mature relational database with broad framework and tooling compatibility.

MySQL vs Similar Relational Databases

FeatureMySQLPostgreSQLMariaDBSQLite
Relational SQL
ACID transactions
JSON support
Multi-user database server
Stored procedures
Replication support
MySQL ecosystem compatibility
Strong extension ecosystem
Embedded single-file database

MySQL is a strong choice when compatibility with the MySQL ecosystem, web frameworks, CMS platforms, and conventional application stacks is important.

PostgreSQL generally offers more advanced extensibility and query capabilities, while MariaDB provides a MySQL-compatible open-source alternative with its own feature set. SQLite is better suited to embedded and lightweight local workloads.

Persistent Storage

A Railway volume keeps MySQL data persistent across deployments.

Persistent data includes:

  • databases
  • tables
  • indexes
  • users
  • privileges
  • stored procedures
  • triggers
  • schemas
  • transaction state

Without persistent storage, database data would be lost when the container is replaced.

Security and Access

For safer application deployments:

  • use Railway private networking whenever possible
  • use the dedicated application account instead of root
  • keep the root password for administrative tasks
  • enable Railway TCP Proxy only when external access is required
  • create additional users with restricted privileges for separate applications

Getting Started After Deployment

  1. Deploy the MySQL Server template.
  2. Wait for the database service to become available.
  3. Use DATABASE_URL for applications running inside Railway.
  4. Use DATABASE_PUBLIC_URL for external database connections.
  5. Connect with MySQL Workbench, DBeaver, DataGrip, TablePlus, or your application.
  6. Verify the server with:
SELECT VERSION();
  1. Create your application tables, indexes, users, and data as required.

Why Deploy MySQL Server 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 MySQL Server on Railway, you get persistent storage, private networking, optional external TCP access, and ready-to-use connection details for modern application and backend workloads.


Template Content

More templates in this category

View Template
Garage S3 Storage
Ultra-light S3 server: fast, open-source, plug-and-play.

PROJETOS
8
View Template
Redis
Self Host Latest Redis with Railway

2
View Template
EasyImg
Simple self-hostable Nuxt.js personal image hosting system.

Muhammad Bilal
0