# 🗄️ MySQL / MongoDB

A database is not required for every setup, but it is recommended for systems that need saved data, history, profiles, or persistent player relationships.

***

### What Database Storage Is Used For

Database storage can be used for:

* Friends data
* Known player profiles
* Ignored players
* Private message data
* HelpOp history
* History-backed systems
* Persistent module data, depending on configuration

{% hint style="info" %}
If your network only uses simple proxy commands, you may not need a database.

If your network uses social systems, history, or persistent data, database storage is recommended.
{% endhint %}

***

### Supported Database Types

NexusProxy supports:

```yaml
none
mysql
mongodb
mongo
```

Use `none` if you do not want persistent database storage.

Use `mysql` or `mongodb` if you want persistent data.

***

### Configuration Location

Database storage is configured in:

```
plugins/NexusProxy/nexusproxy.yml
```

Example memory-only mode:

```yaml
storage:
  database:
    type: "none"
```

***

### MySQL Configuration

Example MySQL configuration:

```yaml
storage:
  database:
    type: "mysql"
    mysql:
      host: "127.0.0.1"
      port: 3306
      database: "nexusproxy"
      username: "root"
      password: "password"
      use_ssl: false
      allow_public_key_retrieval: true
```

***

### MongoDB Configuration

Example MongoDB configuration:

```yaml
storage:
  database:
    type: "mongodb"
    mongodb:
      uri: "mongodb://localhost:27017"
      database: "nexusproxy"
```

You can also use:

```yaml
storage:
  database:
    type: "mongo"
```

***

### Modules That Use Database Storage

| Module                   | Database Usage                                                                         |
| ------------------------ | -------------------------------------------------------------------------------------- |
| Friends                  | Stores persistent friend relationships, friend counts, and player profile data.        |
| Messaging                | Can store ignored players and private message-related data depending on configuration. |
| HelpOp                   | Can store ticket history and history-backed support data.                              |
| PlaceholderAPI Expansion | Uses database data for friends placeholders when configured.                           |

***

### Friends Storage

The Friends module works best with persistent database storage.

A database can store:

* Friend relationships
* Total friends
* Player profile data
* Persistent friend-related information

Redis can be used for online/offline status, but the database stores the actual friend data.

{% hint style="warning" %}
For production networks using Friends, Redis + MySQL or MongoDB is recommended.

Redis handles online presence. The database stores persistent friend data.
{% endhint %}

***

### Messaging Storage

The Messaging module can use database storage for persistent messaging-related data, depending on configuration.

This may include:

* Ignored players
* Private message data
* Message history, depending on your setup

{% hint style="info" %}
If you want ignored players or messaging data to remain after restarts, use MySQL or MongoDB.
{% endhint %}

***

### HelpOp Storage

The HelpOp module can use database storage for ticket history.

This is useful for:

* Reviewing previous support requests
* Tracking repeated issues
* Staff accountability
* Support history
* Discord-connected ticket workflows

{% hint style="warning" %}
If database storage is disabled, HelpOp history may not persist after proxy restarts depending on your configuration.
{% endhint %}

***

### PlaceholderAPI Expansion

The NexusProxy PlaceholderAPI expansion should use the same database settings as NexusProxy if you want friends placeholders to work correctly.

Friends placeholders may include:

```
%nexusproxy_friends_total%
%nexusproxy_friends_online%
%nexusproxy_friends_offline%
%nexusproxy_friends_pending%
%nexusproxy_friends_limit%
```

{% hint style="warning" %}
If the PlaceholderAPI expansion uses different database settings, friends placeholders may return `0` or incorrect values.
{% endhint %}

***

### MySQL vs MongoDB

Both MySQL and MongoDB can be used for persistent NexusProxy data.

Use the one that best fits your network infrastructure.

| Storage | Recommended When                                            |
| ------- | ----------------------------------------------------------- |
| MySQL   | You already use SQL databases or prefer relational storage. |
| MongoDB | You already use MongoDB or prefer document-based storage.   |
| none    | You do not need persistent data.                            |

***

### Runtime Libraries

NexusProxy keeps the main jar lightweight.

When database storage is enabled, NexusProxy can download the required runtime libraries into:

```
plugins/NexusProxy/libraries/
```

This may include:

* MySQL driver
* MongoDB driver
* Other required runtime libraries

{% hint style="info" %}
You normally do not need to manually install database drivers.

NexusProxy handles required runtime libraries when the feature is enabled.
{% endhint %}

***

### Checking Database Status

After configuring the database, restart your proxy or reload NexusProxy.

Then run:

```
/nexusproxy storage
```

Aliases:

```
/nproxy storage
/np storage
```

Use this command to confirm whether the database is connected correctly.

***

### Common Use Cases

#### Persistent friends system

Use MySQL or MongoDB so friendships remain after restarts.

Recommended setup:

* Friends module enabled
* Database enabled
* Redis enabled for online status

***

#### Persistent ignored players

Use database storage if you want ignored players to remain ignored after restarts.

Recommended setup:

* Messaging module enabled
* Database enabled

***

#### HelpOp ticket history

Use database storage if staff should be able to review previous HelpOp requests.

Recommended setup:

* HelpOp module enabled
* Database enabled
* History enabled in `helpop.yml`

***

#### Backend friends placeholders

Use the same database settings in the PlaceholderAPI expansion if you want friends placeholders on backend lobby servers.

***

### Common Issues

#### Database does not connect

Check that:

* The database server is running.
* The host is correct.
* The port is correct.
* The database name is correct.
* The username is correct.
* The password is correct.
* The proxy can reach the database server.
* `/nexusproxy storage` shows the database as connected.

***

#### MySQL authentication fails

Check that:

* The username and password are correct.
* The MySQL user has access to the selected database.
* The database exists.
* `use_ssl` matches your database host requirements.
* `allow_public_key_retrieval` is configured correctly for your MySQL setup.

***

#### MongoDB connection fails

Check that:

* The MongoDB URI is correct.
* The MongoDB server is running.
* Authentication details are correct.
* The selected database name is correct.
* The proxy can reach the MongoDB server.

***

#### Friends data does not save

Check that:

* The Friends module is enabled.
* Database storage is enabled.
* MySQL or MongoDB is connected.
* `/nexusproxy storage` shows the database as connected.
* The player actually created friend data before testing persistence.

***

#### Friends placeholders return 0

Check that:

* The Friends module is enabled.
* Database storage is enabled.
* Friend data exists in the database.
* The PlaceholderAPI expansion uses the same database settings.
* Redis is enabled if checking online friends.
* The expansion is installed on the backend server, not on Velocity.

***

#### HelpOp history does not save

Check that:

* Database storage is enabled.
* HelpOp history is enabled in `helpop.yml`.
* The HelpOp module is enabled.
* `/nexusproxy storage` shows the database as connected.
* NexusProxy was restarted or reloaded after configuration changes.

***

#### Database libraries do not load

Check that:

* NexusProxy can write to `plugins/NexusProxy/libraries/`.
* The proxy has internet access if libraries need to be downloaded.
* File permissions allow library creation and loading.
* The database feature is enabled.
* The proxy was restarted after enabling database storage.

***

### Security Tips

* Never share database passwords publicly.
* Remove credentials before posting configs in support channels.
* Use a dedicated database user for NexusProxy.
* Give the database user only the permissions it needs.
* Do not use root credentials in production if avoidable.
* Use firewall rules to restrict database access.
* Use SSL if your database host requires or recommends it.

***

### Setup Tips

* Use `none` for simple test servers.
* Use MySQL or MongoDB for production systems with persistent data.
* Use Redis together with database storage for cross-proxy friends.
* Use the same database settings in the PlaceholderAPI expansion.
* Restart after changing database type.
* Run `/nexusproxy storage` after every database configuration change.
* Keep credentials private.
* Backup your database before major updates.

***

### Summary

MySQL and MongoDB allow NexusProxy to store persistent data.

They are recommended for Friends, Messaging persistence, HelpOp history, and PlaceholderAPI friends placeholders.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nexusproxy.nemesismc.net/integrations/mysql-mongodb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
