For the complete documentation index, see llms.txt. This page is also available as Markdown.

Setup website database

Creates a new MySQL database for the website and writes its connection details into the website's environment variables, then restarts the application.

Setup website database

post

Creates a new MySQL database for the website and writes its connection details into the website's environment variables, then restarts the application. The platform generates the password (and the database name and user, unless supplied). The password is never returned; the application reads it from the environment.

Written variables: DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD and DATABASE_URL (mysql://user:password@host:port/name, user and password percent-encoded). Existing variables are kept. If the website already has any variable with one of these names the call fails with 422 and nothing is created; the Replace Node.js environment variables endpoint removes them.

After this call the variables are ordinary environment variables: the Replace Node.js environment variables endpoint changes or removes them like any other.

A restart is enough for apps that read environment variables at process start, such as Express or NestJS. Frameworks that bake variables into the build output (Next.js, NEXT_PUBLIC_*) see the new values only after a fresh build (Start Node.js build endpoint).

A password in the request is ignored; the platform always generates it. The optional name and user are identifiers, not secrets.

Authorizations
AuthorizationstringRequired

API Token authentication

Path parameters
usernamestringRequiredExample: u123456789
domainstringRequired

Domain name

Example: mydomain.tld
Body
namestring · min: 1 · max: 25Optional

Optional database name. Generated when omitted. Letters, digits and underscores; must not start with an underscore. Up to 14 characters without the account username prefix (u123456789_), which is added automatically when missing. With the prefix the full name is 12 to 25 characters.

Example: u123456789_blogPattern: ^[A-Za-z0-9][A-Za-z0-9_]*$
userstring · min: 1 · max: 25Optional

Optional database user. Generated when omitted. Letters, digits and underscores; must not start with an underscore. Up to 14 characters without the account username prefix (u123456789_), which is added automatically when missing. With the prefix the full user is 12 to 25 characters.

Example: u123456789_blog_adminPattern: ^[A-Za-z0-9][A-Za-z0-9_]*$
Responses
200

Success response

application/json
env_var_keysstring[]Required

Names of the environment variables written for this database. Values are never returned.

Example: ["DB_HOST","DB_PORT","DB_NAME","DB_USER","DB_PASSWORD","DATABASE_URL"]
post/api/hosting/v1/accounts/{username}/websites/{domain}/databases/setup
POST /api/hosting/v1/accounts/{username}/websites/{domain}/databases/setup HTTP/1.1
Host: developers.hostinger.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 57

{
  "name": "u123456789_blog",
  "user": "u123456789_blog_admin"
}
{
  "database": {
    "name": "u123456789_aB3dE",
    "user": "u123456789_xY9zW",
    "host": "localhost",
    "port": 3306
  },
  "env_var_keys": [
    "DB_HOST",
    "DB_PORT",
    "DB_NAME",
    "DB_USER",
    "DB_PASSWORD",
    "DATABASE_URL"
  ]
}

Last updated

Was this helpful?