
If you are just getting started, think of the stack like this:
You write TypeScript. Prisma handles most SQL details for you.
To connect Next.js (or any backend app) to MariaDB/MySQL, you need:
DB_HOST (database server address)DB_PORT (usually 3306)DB_NAME (database name)DB_USER (database username)DB_PASSWORD (database password)Optional (provider-specific):
The following are placeholder values in the same structure. Do not use real credentials in public docs:
DB_HOST: srv0000.hstgr.ioDB_PORT: 3306DB_NAME: u000000000_exampledbDB_USER: u000000000_exampledbUserDB_PASSWORD: ExamplePass@123Never commit real DB credentials to GitHub.
In Hostinger hPanel:
3306 is the default network port used by MariaDB/MySQL.
Create apps/web/.env.local (or your app's environment file):
DATABASE_URL="mysql://DB_USER:DB_PASSWORD@DB_HOST:3306/DB_NAME"If your password has @, encode it as %40.
Example format:
DATABASE_URL="mysql://u000...User:ExamplePass%40123@srv0000.hstgr.io:3306/u000..."pnpm --filter web add @prisma/client
pnpm --filter web add -D prisma dotenv
pnpm --filter web add @prisma/adapter-mariadb mariadbpnpm --filter web exec prisma init --datasource-provider mysqlIn schema.prisma:
model Healthcheck {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
}Recommended hosted DB flow:
Some shared hosting environments may block prisma migrate dev shadow database behavior.
Create an API route (for example, /api/db-test) and run:
SELECT 1 AS ok;If the response succeeds, your database connection is working.
Two easy options:
Best practice:
pnpm --filter web exec prisma studioThis opens a table editor UI to browse and update rows safely.
Q: Do I run MariaDB inside Next.js? No. In this setup, MariaDB is hosted remotely and Next.js connects to it.
Q: How do I manage tables and data? Use Prisma migrations for structure, and phpMyAdmin/Prisma Studio for data operations.
Q: Is Prisma mandatory? No, but it is highly recommended for beginners because it reduces mistakes and improves maintainability.
.env.localDATABASE_URL to frontend code