← Files Hostinger ConnectorARCHIVED FILE
skills/hostinger-headless/references/DATABASE.md
4.23 KB · Dec 4, 2026 · 00:12 UTC
# Database and runtime — MySQL hosts, env vars, and what to poll Use this when the app needs MySQL, or when a deploy "succeeded" but the app cannot reach its database. Everything here uses the **hosting** MCP operations; Agency Plan differences are at the end. ## 1. Create the database 1. `hosting_databases_create` on the site's `username` with a database name, a user and a password you generate — name and user are prefixed with the account username automatically. 2. Read the full, prefixed `name` and `user` back from `hosting_databases_list`; every other database operation wants the full name. 3. Do not print the password to the user once it is stored, and never commit it. ## 2. Which host the app connects to | Where the code runs | Host | Port | Why | | --- | --- | --- | --- | | PHP on the website | `localhost` or `127.0.0.1` | 3306 | `localhost` uses the MySQL socket; both are granted | | Node.js on the website | `127.0.0.1` | 3306 | `localhost` may resolve to IPv6 `::1`, and not every database user has that grant | | Outside Hostinger (a laptop, another server) | the `host` from `hosting_databases_list` (`srvNNNN.hstgr.io`) | 3306 | needs `hosting_databases_create-remote-connection` for that client's IP first — never `%`, it opens the database to every address on the internet | Do not put the remote `host` into the deployed app — it has no grant for connections that come from the server itself. ## 3. Hand credentials to the app - **Node.js:** environment variables via `hosting_nodejs_replace-environment-variables`. Conventional keys: `DB_HOST=127.0.0.1`, `DB_PORT=3306`, `DB_NAME`, `DB_USER`, `DB_PASSWORD`, plus `DATABASE_URL=mysql://USER:PASSWORD@127.0.0.1:3306/NAME` for ORMs that want one string — URL-encode `USER` and `PASSWORD` there (`encodeURIComponent`), or a password containing `@`, `:`, `/` or `#` breaks the URL. The call is a **full replace**: list the current keys with `hosting_nodejs_list-environment-variables` (values come back masked as `********` — never copy those), then send the complete set with real values. Saving restarts the process; frameworks that bake variables into the build (Next.js, `NEXT_PUBLIC_*`) need a new `hosting_nodejs_start-build` afterwards. - **PHP:** a config file on the server that the app reads (its own `config.php`, WordPress's `wp-config.php`). Ship it with the deploy, keep it out of git. - **Never** in client-side JavaScript, in a committed `.env`, or in chat replies. ## 4. What is asynchronous, and what to poll | You called | Poll this until | Typical wait | | --- | --- | --- | | `hosting_websites_create` | `hosting_websites_list-setups` with the domain reports `status: completed` | up to a few minutes | | `hosting_deploy-js-application` | `hosting_list-js-deployments` shows the build finished | minutes | | `hosting_nodejs_start-build` | `hosting_nodejs_build` state is `completed` or `failed` | minutes | | `wordpress_installations_install`, plugin/theme/core jobs | `wordpress_installations_list` lists the install | 1–2 minutes | | `hosting_databases_repair`, `hosting_websites_delete` | nothing to poll — runs in the background | minutes | | `agency-hosting_website-setups_create` | `agency-hosting_website-setups_status` with `setup_uuid` is `completed` | minutes | Poll with backoff (a few seconds, then tens of seconds). A queued response is not a failure, and re-sending the write does not speed it up. ## 5. When the app is up but broken - Build failed: `hosting_nodejs_build-logs` for the raw log, `hosting_nodejs_analyse-failed-build` for a diagnosis. - Build passed, app errors: `hosting_nodejs_runtime-logs` with a `period` such as `1h`; entries before `last_deployed_at` belong to the previous deploy. - `Access denied for user 'x'@'::1'`: the app used `localhost` from Node.js — set `DB_HOST` to `127.0.0.1`. - PHP limits (memory, upload size): `hosting_php_get`, then `hosting_php_update-options`. ## Agency Plan websites (`agency-hosting_*`) `agency-hosting_databases_create-website` creates the database and its single user; the user is granted on `localhost`, so the PHP app connects to `localhost`. Deploys are synchronous there — `agency-hosting_deploy-php-application` returns when the site is live. Other jobs (SSL, backups) show up in `agency-hosting_websites_list-processes`.
SHA-256: c81159d8d4d9c36604425dd8afee5a22a4cd2286b23ad167ade9db8c478efc7f