Skip to main content

MySQL, MariaDB and PostgreSQL

The three relational engines work the same way in the dashboard. By the end of this page you will have a user, a database, and a client in your lab connected to it.

1. Create a user

  1. Go to Services and click Manage on MySQL, MariaDB or PostgreSQL.
  2. Click Add User (or Create User if you have none yet).
  3. Fill in Username, Password and Confirm Password, then confirm.
The Add User Details dialog with Username, Password and Confirm Password fields.
FieldRules
Username5–16 characters: letters, digits and underscores. Not only digits, and not a reserved name such as root.
PasswordAt least 8 characters. Single quotes (') are not allowed.

The user appears as a card on the Dashboard tab, with its password behind a copy button.

2. Create a database

  1. Open the Database tab.
  2. Choose the Username that will own it.
  3. Type a Database Name. It is automatically prefixed with the user's name and an underscore, so shop owned by alice_dev becomes alice_dev_shop.
  4. On MySQL and MariaDB, choose a Collation (leave the default if unsure).
  5. Click Create Database.

The part you type must be at least 5 characters, and the full name, prefix included, at most 64. Each user can own up to 5 databases.

3. Connect from your lab

Copy the Hostname and Port from Connection Information on the service's Dashboard tab. Then, in your lab's terminal:

MySQL / MariaDB
sudo apt-get install -y mysql-client # or mariadb-client
mysql -h <host> -P <port> -u <user> -p <database>

From code, the usual connection URL is:

mysql://<user>:<password>@<host>:<port>/<database>
PostgreSQL
sudo apt-get install -y postgresql-client
psql -h <host> -p <port> -U <user> -d <database>

From code:

postgresql://<user>:<password>@<host>:<port>/<database>

Enter the password from the user's card when asked. Remember <database> is the full, prefixed name.

Keep the client in your startup script

Anything you apt-get install is gone after a redeploy. Add the client install to your startup script.

Managing what you created

TaskWhere
See a user's passwordIts card on the Dashboard tab
Drop a databaseIts card on the Database tab
Delete a userDelete User on its card — this also deletes every database it owns

If it does not connect

SymptomCheck
Access deniedThe user name and password match the card exactly; you are using the prefixed database name
Connection times outYou are connecting from inside a lab, with the host and port from the service page. From your own computer, use the port forwarding helpers.
Unknown databaseThe database name includes the <user>_ prefix

Do it with an AI assistant

You can also do this by asking an AI assistant connected to your account — see Connect an AI assistant to set one up.

AskWhat the assistant does
“Create a PostgreSQL user called appsvc01”add_service_user
“Create a database called orders for appsvc01”create_database — the platform names it appsvc01_orders
“What databases does appsvc01 have?”list_databases
“Drop appsvc01_orders”delete_database
The password is only in the dashboard

An assistant cannot read back a MySQL, MariaDB or PostgreSQL password — copy it from the user's card on the service page. When creating a database, give the bare name; the platform adds the user prefix.

From the blog

How to connect MySQL to VS Code via Selfmade Ninja Labs is a step-by-step guide with screenshots.

Next