Community GuidesTutorials

Setting Up MySQL

Create the Panel's database, and database hosts that give your servers their own databases.

Introduction

The Panel uses MySQL or MariaDB in two ways:

  • The Panel's own database stores users, servers, and settings. You create it once, when you install the Panel.
  • Database hosts are optional. They let the Panel create databases for game servers, such as for a Minecraft plugin.

This guide uses MariaDB, which the installation guides install. The SQL is the same for MySQL.

Signing In to MariaDB

Run the MariaDB client as root:

mariadb -u root

On a new installation, the system's root user signs in without a password. If you set a root password, add -p and the client asks for it.

Creating the Panel's Database

Create a database and a user for the Panel. Replace yourPassword with a strong, unique password:

CREATE USER 'pterodactyl'@'127.0.0.1' IDENTIFIED BY 'yourPassword';
CREATE DATABASE panel;
GRANT ALL PRIVILEGES ON panel.* TO 'pterodactyl'@'127.0.0.1' WITH GRANT OPTION;

The user can only sign in from 127.0.0.1, the same machine. If the database runs on a different machine from the Panel, use the Panel's IP address instead.

If you followed Getting Started, you already ran these statements.

Creating a Database Host

A database host is a MariaDB server where the Panel creates databases for game servers. It can be the Panel's own MariaDB server or a separate one.

Creating a User for the Panel

The Panel needs a MariaDB user that can create databases and users. Do not reuse the Panel's own database user.

MariaDB only lets a user sign in from the address it was created for, and the Panel connects from the Panel server's IP address. On the database host, sign in to MariaDB and run the statements below. Replace 203.0.113.10 with the Panel server's IP address and yourPassword with a strong, unique password:

CREATE USER 'pterodactyluser'@'203.0.113.10' IDENTIFIED BY 'yourPassword';
GRANT ALL PRIVILEGES ON *.* TO 'pterodactyluser'@'203.0.113.10' WITH GRANT OPTION;

Use the IP address even when the database runs on the Panel's machine. The Panel connects to the address you enter as Host below, and when that is the machine's own IP address, the connection comes from that address, not from 127.0.0.1.

Allowing Connections From Game Servers

Game servers connect from inside their containers, so MariaDB must accept connections from addresses other than 127.0.0.1.

By default, MariaDB only listens on 127.0.0.1. To listen on every address, create /etc/mysql/mariadb.conf.d/99-pterodactyl.cnf:

/etc/mysql/mariadb.conf.d/99-pterodactyl.cnf
[mysqld]
bind-address=0.0.0.0

Then restart MariaDB:

systemctl restart mariadb

If you use a firewall, allow port 3306 only from addresses that need it, such as your nodes. Game servers on the database's machine connect through 172.18.0.1.

Adding the Host to the Panel

Open Admin → Database Hosts, click New Database Host, and fill in:

  • Name: A name to identify the host.
  • Host: The MariaDB server's IP address, such as its public IP address. The Panel connects to this address and shows it to users as the address to connect to, so it must work for both.
  • Port: Usually 3306.
  • Linked Node: Optional. Servers on this node use this host by default.
  • Username and Password: The user you created above.

Click Create Host. The Panel tests the connection before it saves the host.

Creating Databases for Servers

A server's owner creates databases on the server's Databases page, up to the server's Database Limit. The limit is 0 by default. Set it when you create the server, or later on the server's Build tab in the admin area.

The Panel creates the database on the host linked to the server's node, or on any host if none is linked. To stop the Panel from choosing a host that is not linked to the node, set this in your .env file:

PTERODACTYL_CLIENT_DATABASES_ALLOW_RANDOM=false

Administrators can also create databases for a server, and choose the host, on the server's Database tab in the admin area.

Edit on GitHub

Last updated on

On this page