# How To Set Up a Database for Your RedM Server (MariaDB) (/docs/redm/setup-database)



import { Step, Steps } from 'fumadocs-ui/components/steps';

Most RedM frameworks (such as VORP, RSG, and RedEM) require a MySQL-compatible database. This guide covers setting up MariaDB on a Linux server.

> 📝 **Note:** If you are using XGamingServer's managed hosting, a database is provided for you via the panel — you do not need to install MariaDB manually. This guide is for self-hosted or VPS deployments.

Step 1 — Update Your System [#step-1--update-your-system]

Before installing any package, update your system's package list:

```bash
sudo apt-get update && sudo apt-get upgrade -y
```

> ⚠️ **Note:** Always run commands as a user with sudo privileges. It is best practice to keep root SSH access disabled. Read more about [Linux server security](https://blog.avast.com/secure-your-linux-server-avast).

Step 2 — Install MariaDB [#step-2--install-mariadb]

```bash
sudo apt-get install mariadb-server -y
```

Follow any on-screen prompts during installation.

Step 3 — Run the Secure Installation [#step-3--run-the-secure-installation]

Once installed, run the security script to harden your database:

```bash
sudo mysql_secure_installation
```

The script will walk you through:

* Setting a root password
* Removing anonymous users
* Restricting root login to localhost
* Removing the test database
* Reloading privilege tables

> 💡 **Tip:** Answer **Y** (yes) to all questions for a secure setup.

Step 4 — Log In to MariaDB [#step-4--log-in-to-mariadb]

```bash
mysql -u root -p
```

Enter the root password you set above. If you forgot it, a sudo user can bypass authentication with:

```bash
sudo mysql -u root
```

Step 5 — Create a Database User [#step-5--create-a-database-user]

Inside the MariaDB console, create a dedicated user for your RedM server. Replace `youruser` and `yourpassword` with your own values.

```sql
CREATE USER 'youruser'@'%' IDENTIFIED BY 'yourpassword';
SELECT User FROM mysql.user;
GRANT ALL PRIVILEGES ON *.* TO 'youruser'@'%' IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;
```

> 📝 **Note:** Using `%` as the host allows connections from any IP address, which is required if you are connecting remotely (e.g. from HeidiSQL on your PC). For a local-only setup, use `localhost` instead.

Step 6 — Create a Database [#step-6--create-a-database]

Create a dedicated database for your framework:

```sql
CREATE DATABASE redm;
EXIT;
```

Step 7 — Allow Remote Connections [#step-7--allow-remote-connections]

By default, MariaDB only accepts local connections. To allow remote access, edit the configuration file:

```bash
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
```

Find the `bind-address` line and change it from `127.0.0.1` to `0.0.0.0`:

```
bind-address = 0.0.0.0
```

Save and exit with **CTRL+X**, then **Y**, then **Enter**.

Step 8 — Restart MariaDB [#step-8--restart-mariadb]

Apply the configuration change:

```bash
sudo systemctl restart mariadb
```

Verify it is running:

```bash
sudo systemctl status mariadb
```

Step 9 — Open the MySQL Port [#step-9--open-the-mysql-port]

MariaDB uses port **3306**. Open it in your firewall with iptables:

```bash
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
```

> ⚠️ **Warning:** Opening port 3306 exposes your database to the internet. Make sure you are using a strong password and not using the root account for your server connection.

You can verify the port is reachable using [portchecker.co](https://portchecker.co).

Connecting Your Framework [#connecting-your-framework]

Your database connection string will look like this (used in `oxmysql` or framework config):

```
mysql://youruser:yourpassword@your-server-ip/redm
```

Or in connection string format:

```
server=your-server-ip;database=redm;userid=youruser;password=yourpassword;
```

> 💡 **Tip:** Need help setting up the database? Join our [Discord](https://discord.xgamingserver.com) for support.

Next Steps [#next-steps]

* [Install VORP Framework](/docs/redm/install-vorp-framework)
* [Install Resources](/docs/redm/install-resources)
* [Configure Your Server](/docs/redm/configure-your-server)
