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.
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.
API Token authentication
u123456789Domain name
mydomain.tldOptional 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.
u123456789_blogPattern: ^[A-Za-z0-9][A-Za-z0-9_]*$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.
u123456789_blog_adminPattern: ^[A-Za-z0-9][A-Za-z0-9_]*$Success response
Names of the environment variables written for this database. Values are never returned.
["DB_HOST","DB_PORT","DB_NAME","DB_USER","DB_PASSWORD","DATABASE_URL"]Unauthenticated response
Validation error response
Error response
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?