Skip to main content

MySQL, MariaDB and PostgreSQL

The three relational engines work the same way in the dashboard. This page shows you how to create a user and a database, and how to connect to the database from a client in your lab.

1. Create a user​

  1. Go to Services and select Manage on MySQL, MariaDB or PostgreSQL.
  2. Select Add User (or Create User if you have none yet).
  3. Fill in Username, Password and Confirm Password, then confirm.
Shown on labs.selfmade.ninja, the Selfmade Ninja Academy platform. On your own platform you will see your own domain and data.
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 (if you are not sure, leave the default).
  5. Select Create Database.

The part you type must be at least 5 characters long, and the full name, including the prefix, can be at most 64 characters. Each user card shows how many databases the user owns and how many it can own. At the limit, you see Database limit exceeded for the user.

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 that <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 username and password match the card exactly, and 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 you create a database, give only the 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​