> For the complete documentation index, see [llms.txt](https://realisticnode.gitbook.io/rnsetups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://realisticnode.gitbook.io/rnsetups/rnchatgames/reference/database.md).

# Database (SQLite / MySQL)

The database keeps points, wins per game, best times, records, win streaks, the wins log and the rewards of players who left.

## SQLite (default)

One file, `data/database.db`, nothing to set up. Best for a single server.

## MySQL / MariaDB

To share the stats between several servers:

```yaml
storage:
  type: MYSQL
  table-prefix: rncg_        # start of every table name
  mysql:
    host: localhost
    port: 3306
    database: minecraft
    username: root
    password: ''
    properties: useSSL=false&characterEncoding=utf8
    pool-size: 5
```

{% hint style="warning" %}
Changing `storage` needs a **server restart**. Check the console: `Connected to the MySQL database.`
{% endhint %}

## Moving the stats from SQLite to MySQL

MySQL starts empty. To bring the stats you had in SQLite:

1. Set `type: MYSQL`, fill the `mysql` section and restart.
2. Run `/rncg import sqlite`: it shows what SQLite and MySQL have, without changing anything.
3. Run `/rncg import sqlite confirm` to copy everything (players, stats per game, records, wins log, streak and pending rewards).

If MySQL already has data, it is **replaced** by the SQLite data (you are warned first). The copy is done in one step: if anything fails, MySQL stays as it was. Players who are online see their imported stats right away.

## Online and offline mode

A player has a different UUID on an online-mode and an offline-mode server. When a server changes between both, the same player would appear twice in the rankings. rnChatGames joins them automatically the next time the player joins: points and wins are added up, the best times and streaks are kept and the wins log moves to the current UUID.

It only happens when it is surely the same person (one of the two records has an offline-mode UUID). Two premium accounts that had the same name are never joined.

## Backups

* SQLite: stop the server and copy `data/database.db` (or copy `database.db`, `database.db-wal` and `database.db-shm` together).
* MySQL: use the backup of your database host.
