Plugins such as LuckPerms or CoreProtect store their data in a MySQL database. We'll set up MariaDB as a Pterodactyl database host so users can create a database for their server with one click in the Panel.
What you'll need
How it works#
When a user clicks New Database in their server's Databases tab, the Panel connects to the database host and creates a database s<server ID>_<name> and a user u<server ID>_<random characters> with a random password. The game server then connects to this database from its container.
The key word is container. Inside a container, the address 127.0.0.1 means the container itself, not the VPS. So the game server won't find MariaDB at 127.0.0.1. On the same VPS, however, containers can reach the server itself at 172.18.0.1 (the pterodactyl0 interface created by Wings). That's the address we'll use for the database host:
| Who connects | From | To |
|---|---|---|
| Panel (creates databases and users) | from the VPS, source address 172.18.0.1 | 172.18.0.1:3306 |
| Game server (plugin) | from the container, address 172.18.0.x | 172.18.0.1:3306 |
Check that the interface exists (Wings must have run at least once):
ip -4 addr show pterodactyl0ip -4 addr show pterodactyl0– prints the IPv4 address of thepterodactyl0interface.
The output contains the line inet 172.18.0.1/16. If the command says Device "pterodactyl0" does not exist, Wings hasn't run yet; finish installing it first.
An account for the Panel#
The Panel needs a MariaDB account that can create databases and users and grant them privileges. Don't use the pterodactyl account from the Panel installation; it only has privileges on the panel database.
Generate a strong password using only letters and digits (password generator).
Log in to MariaDB:
bash mariadbCreate the account. Replace
<DB_HOST_PASSWORD>with the password from step 1:SQL CREATE USER 'pterodactyluser'@'172.18.0.1' IDENTIFIED BY '<DB_HOST_PASSWORD>'; GRANT ALL PRIVILEGES ON *.* TO 'pterodactyluser'@'172.18.0.1' WITH GRANT OPTION; exit
| Part | What it means |
|---|---|
'pterodactyluser'@'172. | The user may log in only from 172.18.0.1, that is, only from this VPS through the Docker interface. Nobody can log in with this account from the internet, not even with the right password. |
ALL PRIVILEGES ON *.* | All privileges on all databases. The Panel needs to create and delete databases and users. |
WITH GRANT OPTION | The account may grant privileges to other users. Without it, the Panel couldn't give a new database user access to a new database and creating it would fail. |
This account is effectively a database administrator
Anyone who knows its password and gets onto the VPS can read and delete all databases, including the Panel's own. That's why the account only allows host 172.18.0.1, and you shouldn't enter the password anywhere other than the Panel. The Panel stores the password encrypted with the APP_KEY key.
Making MariaDB listen on the network#
After installation, MariaDB only listens on 127.0.0.1 (the bind-address setting in /etc/). Containers can't reach it there. You change this with your own file that is loaded after the default one and overrides it. That way the default file stays untouched, even after package updates.
Create the file:
bash nano /etc/mysql/mariadb.conf.d/60-pterodactyl.cnfPaste the content, save and close the editor:
/etc/ mysql/ inimariadb.conf.d/ 60-pterodactyl.cnf [mysqld] bind-address = 0.0.0.0
| Setting | What it does | Recommended value | When to change |
|---|---|---|---|
[mysqld] | The option group read by the database server (MariaDB 10.11 on Ubuntu and 11.8 on Debian). | – | Never. |
bind-address | Which addresses MariaDB accepts connections on. 0.0.0.0 = all IPv4 addresses of the VPS. | 0.0.0.0 | If you don't want network access, go back to 127.0.0.1 (delete this file). |
Restart MariaDB and check where it listens:
bash systemctl restart mariadb ss -tlnp | grep 3306ss -tlnp– lists listening TCP ports and programs;grep 3306picks the MariaDB line.
You'll see
0.0.0.0:3306and the process namemariadbd.
Why not just bind-address = 172.18.0.1
MariaDB can listen on a specific address too. But the pterodactyl0 interface is only created by Docker once it starts. If MariaDB came up first when the VPS boots, it wouldn't find the address and wouldn't start. Using 0.0.0.0 and closing outside access with the firewall is safer.
Firewall#
MariaDB now also listens on the VPS's public IP address. Port 3306 must stay closed to the internet. Game server database users are allowed to connect from anywhere (%) by default, so they could be logged into from outside.
Firewall in the customer area (guide):
- Block everything except allowed mode: don't add any rule for port
3306. It's closed. - Allow everything mode: add the rule Inbound · Drop · TCP · port
3306.
Connections from containers to the VPS stay inside the server, and the customer area firewall doesn't affect them.
UFW on the VPS: if you have it enabled, it blocks connections from containers too. Allow port 3306 only from the Docker interface:
ufw allow in on pterodactyl0 to any port 3306 proto tcpallow in on pterodactyl0– allows incoming traffic only from thepterodactyl0interface (from game server containers).to any port 3306 proto tcp– only to TCP port 3306.
The database host in the Panel#
- In the Panel's admin area, click Databases on the left and then Create New.
- Fill in the form:
| Field | What to enter | Why |
|---|---|---|
| Name | For example local-mariadb | A name for the host, for you; 1–60 characters. |
| Host | 172.18.0.1 | The address the Panel connects to and also the address users see as their database's Endpoint. That's why it's not 127.0.0.1. |
| Port | 3306 | The MariaDB port. |
| Username | pterodactyluser | The account from An account for the Panel. |
| Password | <DB_HOST_PASSWORD> | The password for this account. |
| Linked Node | Your node | Databases that users of servers on this node create themselves are created on this host. Without a link, the Panel picks any host at random. In the admin area, this host is offered as the default for servers on this node. |
- Click Create. The Panel tries to connect to the host right away. If that fails, it shows an error and doesn't save the host (see Troubleshooting).
The server's database limit#
A user can only create as many databases as you allow. The default limit is 0, in which case the Databases tab says Databases cannot be created for this server.
- In the admin area, open Servers and click the server.
- Go to the Build Configuration tab.
- In Application Feature Limits, set Database Limit, for example
2. - Click Update Build Configuration.
Creating a database from the server#
This part is done by the server's user:
- In the Panel, open the server and its Databases tab.
- Click New Database.
- Fill in Database Name, for example
luckperms. The resulting name will bes<ID>_luckperms. Letters, digits,-and_are allowed, 3–48 characters long. - The Connections From field sets where the database user may connect from. A safe value for game servers on this node is
172.18.0.%(all containers). An empty field means%, i.e. from anywhere. - Click Create Database.
- Click the eye icon next to the new database. It shows the Endpoint (
172.18.0.1:3306), Connections from, Username, Password and JDBC Connection String.
Enter these details in the plugin's configuration. Most plugins want the address, database name, user and password separately. For example, LuckPerms in plugins/:
storage-method: MariaDB
data:
address: 172.18.0.1:3306
database: s1_luckperms
username: u1_AbCdEfGhIj
password: '<PASSWORD_FROM_PANEL>'storage-method– the storage type;MariaDBorMySQL.address– the Endpoint from the Panel (address and port).database,username– the exact values from the Panel (made up in this example).password– the password from the Panel, in single quotes because of special characters.
Plugins that want a single string (JDBC URL) get the value from the JDBC Connection String field in the form jdbc:. More on databases for Minecraft plugins: MySQL for plugins.
Verification#
From the VPS, check that the server's user can connect via the address the containers use:
mariadb -h 172.18.0.1 -u <DB_USER> -p <DB_NAME> -e "SELECT 1;"-h 172.18.0.1– connects over TCP to the Docker interface.-u <DB_USER>– the user from the Panel (for exampleu1_AbCdEfGhIj).-p– asks for the password.<DB_NAME>– the database from the Panel (for examples1_luckperms).-e "SELECT 1;"– runs a simple query and exits.
You'll see a table with the number 1. If you entered 172.18.0.% in Connections From, this test from the VPS passes, because a connection to 172.18.0.1 has the source address 172.18.0.1.
Finally, restart the game server and check its console to make sure the plugin connected to the database without errors.
Advanced: the database on another server#
If MariaDB runs on a different VPS than the Panel and Wings:
- Create the Panel account with the IP address of the VPS running the Panel (
'pterodactyluser'@'203.).0. 113. 10' - In the Host field, enter the IP address of the database server. Both the Panel and the containers on the nodes must be able to reach it.
- In the database server's firewall, allow port
3306only from the IP addresses of the Panel and the nodes (a rule with Source IP / range filled in). - Set Connections From for server database users to the node's IP address.
Troubleshooting#
The Panel reports Access denied for user 'pterodactyluser'@'172.18.0.1' when creating the host#
The password is wrong, or the user doesn't have host 172.18.0.1. Check the accounts:
SELECT User, Host FROM mysql.user WHERE User = 'pterodactyluser';If the host is different, delete the account (DROP USER 'pterodactyluser'@'<OLD_) and create it again as described in An account for the Panel.
Connection refused or Can't connect to … server on '172.18.0.1'#
MariaDB isn't listening on this address. Check ss -tlnp | grep 3306 (it must show 0.0.0.0:3306) and the 60-pterodactyl.cnf file. Restart MariaDB after any change.
The plugin reports Communications link failure or a connection timeout#
The plugin couldn't reach the database. Most often the plugin configuration says localhost or 127.0.0.1 instead of 172.18.0.1, or UFW blocks the connection from the container (see Firewall).
The plugin reports Access denied for user 'u1_…'@'172.18.0.x'#
Connections From contains an address the container doesn't connect from. Delete the database and create it again with 172.18.0.%, or generate a new password for the database in the Panel if you entered it incorrectly.
The user doesn't see the New Database button#
The server has a Database Limit of 0, or the limit is used up. Change it as described in The server's database limit.
Summary
- Game server containers see the VPS at
172.18.0.1, not at127.0.0.1. - The Panel account has
WITH GRANT OPTIONand may only log in from172.18.0.1. - MariaDB listens on
0.0.0.0thanks to the60-pterodactyl.cnffile; port3306is closed to the internet by the firewall. - The Database Host in the Panel has the address
172.18.0.1, which users see as the Endpoint. - Set a Database Limit for servers, otherwise users can't create databases.