DokployD
Dokploy2y ago
4 replies
juanlul

Help needed, mysql2 driver cannot connect to the mysqldatabase (nextjs, drizzle,mysql)

I have project which contains mysql and nextjs app. The mysql container is running fine.
When i try to deploy my nextjs it fails on the build because it cannot find the hostname
here's the error message:
Error: getaddrinfo ENOTFOUND schoolput-database-112c11
at e.createConnection (/app/.next/server/chunks/5516.js:5:60532)
at /app/.next/server/chunks/1323.js:6:6804
at t.a (/app/.next/server/webpack-runtime.js:1:918)
at 90469 (/app/.next/server/chunks/1323.js:6:6710)
at t (/app/.next/server/webpack-runtime.js:1:143)
at /app/.next/server/chunks/1323.js:6:12167
at t.a (/app/.next/server/webpack-runtime.js:1:918)
at 28695 (/app/.next/server/chunks/1323.js:6:12115)
at t (/app/.next/server/webpack-runtime.js:1:143)
at /app/.next/server/app/(auth)/signup/page.js:1:3791 {
code: 'ENOTFOUND',
errno: -3008,
sqlState: undefined
}

and here's my create connection file
import { drizzle } from "drizzle-orm/mysql2";
import * as schema from "./schema/schema";
import mysql from "mysql2/promise";

const connection = await mysql.createConnection({
  host: process.env.DB_HOST,
  port: 3306,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
});

export const db = drizzle(connection, {
  schema,
  mode: "default",
  logger: true,
});

here's my env
DB_HOST=schoolput-database-112c11

Thanks
image.png
Was this page helpful?