# Database hosts

> Add MySQL, MariaDB or PostgreSQL hosts that users create server databases on, scope them to a node, install phpMyAdmin, and run panel migrations.

Source: https://featherpanel.com/docs/admin/databases/

Database hosts are the MySQL, MariaDB or PostgreSQL servers that users create databases on for their game servers.
The panel itself uses its own database, which you set up during installation; this page is about the hosts for
customers.

## Preparing a host

Create an account the panel can log in with from the panel machine. It must be able to create databases and users
and grant privileges, because each server database gets its own user with `GRANT ALL PRIVILEGES` on that database. For
MySQL or MariaDB:

```sql
CREATE USER 'featherpanel'@'PANEL_IP' IDENTIFIED BY 'a-long-password';
GRANT ALL PRIVILEGES ON *.* TO 'featherpanel'@'PANEL_IP' WITH GRANT OPTION;
FLUSH PRIVILEGES;
```

Server database users are created for `%`, so the database must listen on an address game servers can reach, not only
`127.0.0.1`. Firewall the port to the hosts that need it.

## Adding a host

Admin area, Node Databases (or Manage node databases on a node), Add Database:

- **Database Name**, a label for the host.
- **Database Type**: MySQL, MariaDB or PostgreSQL.
- **Host** and **Port** (3306 for MySQL and MariaDB, 5432 for PostgreSQL).
- **Database Hostname (optional)**, shown to users in their credentials instead of the host.
- **Username** and **Password**.
- **Availability.** All nodes (global) shows the host to every server. Single node only shows it to servers on that
  node, and new databases on that node go there. You can also scope a host to a FeatherQuilld web node for WebSpaces.

Check Health tests the connection. To change the password later, fill it in; leaving it blank keeps the current one.

How many databases a server can create is its Database Limit, set on the server's Limits tab.

## Database Management

Admin area, Database Management covers the panel's own database:

- Engine version, uptime, queries per second, connections and network counters.
- **Run Migrations** applies pending schema changes after an update or plugin install and shows the output. Back up
  first.
- **Install phpMyAdmin.** After that every database in the panel gets an Open in phpMyAdmin button, so users can manage
  tables and import dumps in the browser. Delete phpMyAdmin removes it again.

## API

| Method | Path | Permission |
| --- | --- | --- |
| GET | `/api/admin/databases`, `/api/admin/databases/node/{nodeId}` | admin.databases.view |
| PUT | `/api/admin/databases` | admin.databases.create |
| POST | `/api/admin/databases/test-connection` | admin.databases.create |
| GET | `/api/admin/databases/{id}/health` | admin.databases.view |
| PATCH, DELETE | `/api/admin/databases/{id}` | admin.databases.edit, admin.databases.delete |
| POST | `/api/admin/databases/management/migrate` | admin.databases.manage |
| POST | `/api/admin/databases/management/install-phpmyadmin` | admin.databases.manage |

## Frequently asked questions

### Which database servers are supported?

MySQL, MariaDB and PostgreSQL.

### What privileges does the database host user need?

The panel creates a database and a user for every server database and grants that user all privileges on it, so the host account needs to create databases and users and grant privileges.
