Create and manage server databases
Create a MySQL-compatible database for your server, read its credentials, browse its tables, rotate its password and delete it.
In the dashboard
Many plugins and mods keep their data in a MySQL database: permissions, economy balances, player statistics. The Databases tab creates MariaDB databases for your server, which work with any plugin that asks for MySQL. We create each one on a shared MariaDB host in the server's location.
Before you begin
Section titled Before you begin- Your plan sets how many databases the server can have. The Databases card shows how many slots you have used, and the Size and add-ons card on the Billing tab shows the server's Database slots. When every slot is in use, the tab offers the
Extra Databaseadd-on, which raises the limit by one. A boost from a brand's Medal quest can add databases too: a level on the brand's paid ladder adds them to the plan's limit, and on a free server a level can unlock databases the free plan leaves out. Databases made while boosted keep working after the level drops. - On a server someone shared with you, the owner must have given you the Databases permission.
Create a database
Section titled Create a database- In the dashboard, go to App Deployment and open the server, then the Databases tab.
- Select New database…. A page opens with the heading Create a database. Cancel or the All databases link takes you back to the list.
- Under Name, enter a Name suffix that says what the database is for, such as
statsorluckperms. Use lowercase letters, digits and underscores, up to 48 characters. - Under Database host, leave the number as it is. We always use the host in the server's location, whatever it says.
- Select Create database.
- The page shows the new database's credentials, with the password masked. Copy what you need, then select I have saved them to return to the list.
The database's name is srv_, your server's number, an underscore and your suffix, such as srv_1234_stats. We create a user for it with a random 24-character password. If we cannot create it, the page keeps what you entered and says why under the form.
Connect a plugin to it
Section titled Connect a plugin to it- Select the database's name, or open the menu at the end of its row and select Show credentials.
- Copy the values into your plugin's configuration file. Select Reveal to see the password, or Copy all to copy every value at once.
- Restart the server so the plugin connects.
- Host
- The address of the database server. The Host column in the list shows the same address followed by the port.
- Port
- Usually
3306. - Database
- The database's name, such as
srv_1234_stats. - Username and Password
- The database user. You can show the password again at any time.
- Connection URI
- The same details in one
mysql://address, for plugins that ask for a URL. It includes the password. - JDBC
- The same details as a
jdbc:mysql://address, for Java plugins that ask for one. It includes the password.
Browse a database's tables
Section titled Browse a database's tablesYou can read what a plugin stored without a MySQL client. The dashboard only reads tables: to change a row, connect a MySQL client with the database's credentials.
- On the Databases tab, select Browse tables in the database's row. The button shows once the database is ready.
- The Tables card lists each table with its Rows and Size. The row counts are estimates from MariaDB, so they can be a little off on a busy table. A view shows View beside its name and no count.
- Select a table to read its rows, 50 at a time. Previous and Next move between pages, and the footer says which rows you see, such as
Rows 1–50 of about 1,284,113. - To find a row, type in the search box (
Search every column). We look for the text in every column except binary data, and the toolbar says how many rows match, such as3 matches. - To sort, select a column's heading: once for A to Z, again for Z to A, and a third time for the default order. On a phone, choose the order from the list above the rows, which starts at
Default order. - To save the table, select Download CSV.
An empty value shows as NULL. A value longer than 60 characters is cut short, and pointing at it shows more of it. The CSV file has every value in full.
Download CSV saves the whole table, up to its first 10,000 rows, in the order of its primary key. It does not use the search or the sort. On a table with more rows, the page says Download CSV saves the first 10,000 rows of the table.
All databases goes back to the list, and the database's name above a table goes back to its tables.
Rotate the password
Section titled Rotate the passwordRotate the password when you think someone else has seen it.
- Open the menu at the end of the database's row and select Rotate password….
- Select Rotate password.
- Copy the new password from the window that opens, and put it in every plugin that uses the database.
Important
The old password stops working straight away. Plugins that use it cannot reach the database until you give them the new one and restart the server.
Delete a database
Section titled Delete a database- Open the menu at the end of the database's row and select Delete database….
- Type the database's name to confirm, then select Delete database.
We delete the database and every table in it, and you cannot undo it. A snapshot holds the server's files, not its databases, so export anything you want to keep first with a plugin or a MySQL client.
Result
Section titled ResultA new database shows in the list with its user under the name, and its credentials show on the page that created it. The Status column shows each database's state, and a message confirms each action, such as Database created. or Database deleted.
Troubleshooting
Section titled Troubleshooting- The status shows a failure and Try again
- We could not finish creating, rotating or deleting the database. The error shows under its name. We keep trying on our own, and Try again tries at once. If it keeps failing, contact support with the error.
- New database… is greyed out
- Every database slot is in use. Delete a database you no longer need, or select Add… on the
Extra Databasecard above the list to raise the limit by one. The Size and add-ons card on the Billing tab sells the same add-on, and Add-ons explains how it is billed. On a server someone shared with you, only its owner can add it. Database limit reached (3/3)- The same limit, reached through the API or another tab. The numbers are your database count and the server's limit.
A database named srv_1234_stats already exists on this host- The server already has a database with that suffix. Choose another suffix.
The database host is unreachable. We will keep trying; you can also retry from the list.- The database host did not answer. We keep trying, and the database finishes when the host is back. Select Try again to retry sooner.
No database host on this server's node- Databases are not available where your server runs. Contact support.
Retry the failed create before rotating the password- The database was never created. Select Try again first, then rotate the password.
- Could not load the tables or Could not load the rows
- The database host did not answer, or MariaDB refused the request. The reason shows under the title. Select Try again.
Stopped: the statement ran longer than 15 seconds. Narrow it with a WHERE or LIMIT, or run it from a client of your own.- A search or a sort on a very large table took longer than we allow. Search for something more exact, or read the table from a MySQL client.
Could not download the table- The download failed, and the reason shows under it. You can download 12 CSV files from a server every five minutes.
Too many requests for this action. Try again later.- You created more than 24 databases on this server in 60 seconds, or opened more than 240 pages of tables in a minute. Wait a minute and try again.
Related
Section titled Related- Manage server files to edit the plugin's configuration file.
- Share a server with other users explains the Databases permission.
- Server limits and rate limits
With the API
Section titled With the APICreate a database with POST /api/v1/client/servers/{uuid}/databases. The body takes name_suffix (lowercase letters, digits and _, up to 48 characters) and remote, a MariaDB host pattern for where the user may connect from. remote defaults to %, which allows any address. We choose the database host, so any database_host_id you send is ignored.
curl -X POST https://api.coritan.com/api/v1/client/servers/$SERVER/databases \
-H "Authorization: Bearer $CORITAN_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: create-stats-db-1" \
-d '{"name_suffix": "stats"}'
The response (201) carries id, name, username, password, host, port, uri, jdbc and status. With an Idempotency-Key header, sending the same request again returns the same database instead of a second one. See Idempotency.
The other routes use the database's id:
| Route | What it does |
|---|---|
GET /api/v1/client/servers/{uuid}/databases |
Lists the server's databases, without passwords. |
GET /api/v1/client/servers/{uuid}/databases/{db_id}/credentials |
Returns one database with its password, uri and jdbc. |
POST /api/v1/client/servers/{uuid}/databases/{db_id}/rotate-password |
Sets a new password and returns it. |
POST /api/v1/client/servers/{uuid}/databases/{db_id}/retry |
Finishes a create, rotation or deletion that failed. |
DELETE /api/v1/client/servers/{uuid}/databases/{db_id} |
Deletes the database and everything in it. |
Each database has a status: ready, provisioning while we create it, rotating, deleting, or failed. busy is true during the three in-between states, and last_error holds the reason for a failure. Errors carry an error code and a message: database_limit_reached, database_name_taken, database_busy and database_not_ready answer 409, and database_host_unreachable answers 503.
On a server shared with you, listing needs database.read, creating and retrying need database.create, rotating needs database.update, reading the password needs database.view_password and deleting needs database.delete. The Databases permission in the dashboard grants all five.
Tables and rows
Section titled Tables and rowsThese routes connect to the database as its own user, so they can do what that user can. They need database.view_password, because the password alone lets anyone connect and do the same.
| Route | What it does |
|---|---|
GET /api/v1/client/servers/{uuid}/databases/{db_id}/tables |
Lists the tables in tables, each with name, estimated_rows, size_bytes, is_view and comment. |
GET /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/columns |
Returns one table's columns and its primary key. |
GET /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/rows |
Returns a page of rows. It takes limit (1–100, default 50), offset, search (up to 200 characters, looked for in every column except binary data), sort (a column's name) and direction (asc or desc). |
GET /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/export.csv |
Downloads up to 10,000 rows as CSV, in primary key order. X-Export-Rows says how many it holds, and X-Export-Truncated: 1 means the table has more. |
POST /api/v1/client/servers/{uuid}/databases/{db_id}/query |
Runs the SQL in sql, up to 65,536 characters, and returns one block of results for each statement. |
POST /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/rows |
Adds a row from values, which maps column names to values. It answers 201. |
PATCH /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/rows |
Changes the row whose whole primary key is in key to the values you send. |
POST /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/rows/delete |
Deletes the row whose whole primary key is in key. |
POST /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table}/truncate |
Deletes every row and keeps the table. |
DELETE /api/v1/client/servers/{uuid}/databases/{db_id}/tables/{table} |
Deletes the table and its rows. |
curl "https://api.coritan.com/api/v1/client/servers/$SERVER/databases/$DB/tables/players/rows?search=ender&sort=username&direction=desc" \
-H "Authorization: Bearer $CORITAN_TOKEN"
A page carries columns, rows (each row a list in the order of columns), primary_key, limit, offset, total and total_exact. total is an exact count after a search and on a table of up to 250,000 rows, and MariaDB's estimate otherwise. A value longer than 4,096 characters is cut short, and truncated_cells counts how many were.
A statement runs for at most 15 seconds. A table that does not exist answers 404 with table_not_found, a sort that names no column answers 400 with column_not_found, and a change to a table with no primary key answers 409 with row_not_addressable. When MariaDB refuses a statement, the answer is 400 with statement_failed, its own message in mariadb_message and a plainer one in hint.
Each account can open 240 pages of tables, columns or rows on a server in a minute, make 120 changes to rows or tables in a minute, run 60 scripts in a minute and download 12 CSV files in five minutes.