> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Create database

> Create a managed MongoDB, MySQL, PostgreSQL or Redis database with POST /v2/databases. The password and certificate are returned once, so save them.

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  The API key for your account. You can find this in your [account settings](https://squarecloud.app/en/account/security).
</ParamField>

Requires an API key with the `databases:write` [scope](/en/api-reference/authentication#scopes).

Provisions a managed database on Square Cloud (MongoDB, MySQL, PostgreSQL or Redis), picks the cluster with the most available RAM, and allocates a public DNS record (`square-cloud-db-<id>.squareweb.app`) pointing to it. The `password` and `certificate` in the response are shown only once, save them immediately since neither can be retrieved again later, only reset via [Reset Credentials](/en/api-reference/endpoint/databases/credentials/reset).

Database hosting requires a Standard, Pro or Enterprise plan. The requested `memory` must be at least the engine's minimum (512 MB for Redis, 1024 MB for MongoDB, MySQL and PostgreSQL) and cannot exceed your account's available memory. Rate limited to 1 creation every 3 seconds per user. A creation that fails leaves nothing behind, so it is safe to try again.

Once created, use [Edit Database](/en/api-reference/endpoint/databases/edit) to rename it or resize its memory, and [Create Snapshot](/en/api-reference/endpoint/databases/snapshots/create) to back it up.

## Parameters

<ParamField body="name" type="string" placeholder="database name" required>
  The name of the database. 1–32 characters: letters, numbers, underscores (`_`), hyphens (`-`) and spaces, and must include at least one letter, number or underscore.
</ParamField>

<ParamField body="memory" type="int" placeholder="RAM(in MB)" required>
  The RAM allocated to it, in MB, as a whole number. Redis minimum is 512 and Mongo, 1024.
</ParamField>

<ParamField body="type" type="string" placeholder="database(mongo,redis)" required>
  The database type, mongo, redis, postgres, mysql.
</ParamField>

<ParamField body="version" type="string" placeholder="Version number" required>
  The version of the database.\\
  Postgres 17, MySQL 9, Mongo 8, Redis 8.
</ParamField>

## Response

<ResponseField name="status" type="string">
  Indicates whether the call was successful: `success` if it was, `error` if not.
</ResponseField>

<ResponseField name="response" type="object">
  The contents of the response.

  <Expandable title="Toggle object">
    <ResponseField name="id" type="string">
      The ID of the database.
    </ResponseField>

    <ResponseField name="name" type="string">
      The name you chose for the database
    </ResponseField>

    <ResponseField name="memory" type="int">
      The memory allocated to the database
    </ResponseField>

    <ResponseField name="cpu" type="int">
      The number of vCPUs allocated to the database
    </ResponseField>

    <ResponseField name="type" type="string">
      The type of the database.
    </ResponseField>

    <ResponseField name="password" type="string">
      The password for the database.
    </ResponseField>

    <ResponseField name="certificate" type="string">
      The certificate needed to connect to it. You can save it in a `.pem` file. It can be `null`.
    </ResponseField>

    <ResponseField name="connection_url" type="string">
      The URL to connect to the database. The user is `default` for MongoDB and Redis, and `squarecloud` for PostgreSQL and MySQL.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json theme={"system"}
  {
    "status":"success",
    "response": {
      "id": "a14b8d5e1cb7405a851eb4c075506121",
      "name": "test",
      "memory": 1024,
      "cpu": 2,
      "type": "mongo",
      "password": "PASSWORD",
      "certificate": "CERTIFICATE_IN_BASE_64_FORMAT",
      "connection_url": "mongodb://default:PASSWORD@square-cloud-db-ID.squareweb.app:PORT"
      }
  }
  ```
</ResponseExample>

## Common errors

| Code | HTTP | Meaning |
| - | - | - |
| `INVALID_NAME` | 400 | The name fails the 1-32 character validation. |
| `INVALID_DATABASE_TYPE` | 400 | `type` is not one of `mongo`, `mysql`, `redis`, `postgres`. |
| `INVALID_DATABASE_VERSION` | 400 | `version` is not a supported version for the chosen `type`. |
| `INSUFFICIENT_MEMORY` | 400 | The requested `memory` is not a whole number of MB, is below the engine's minimum or exceeds the account's available memory. |
| `CLUSTER_SELECTION_FAILED` | 400 | No cluster with enough capacity could be selected. |
| `DATABASE_CREATION_FAILED` | 400 / 500 | Provisioning failed, or the cluster response was incomplete. Nothing is left behind, so you can retry. |
| `UPGRADE_REQUIRED` | 403 | The account has no active plan, or its plan does not include database hosting. |
| `CLUSTER_MAINTENANCE_TRY_LATER` | 503 | Database provisioning is temporarily unavailable due to maintenance. |

## Related

* CLI: [`squarecloud db create`](/en/cli-reference/databases#squarecloud-db-create)
* SDKs: [`api.databases.create()`](/en/sdks/js/databases) (JavaScript), [`client.databases.create()`](/en/sdks/py/databases) (Python), [`c.Databases.Create()`](/en/sdks/go/databases) (Go)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.