MySQL error help?

when I run server locally I got Error: Unknown database '<db>' error can anybody help me fix that?

I’m not sure if I understand what you trying to do - are you trying to setup the application database, or are you trying to setup database source in Metabase?

I want to connect MySQL server locally using nodejs backend and I’m using xamp to spin MySQL server locally but when I run my server I got Error: Unknown database 'database name'.
My connection code -

const mysql = require('mysql2');

// environment variable config
const dotenv = require('dotenv');
dotenv.config();

const pool = mysql.createPool({
  connectionLimit: 10,
  host: process.env.HOST,
  user: process.env.USER,
  password: process.env.PASSWORD,
  database: process.env.DATABASE,
  multipleStatements: true,
});

// Ping database to check for common exception errors.
pool.getConnection((err, connection) => {
  if (err) {
    if (err.code === 'PROTOCOL_CONNECTION_LOST') {
      console.error('Database connection was closed.');
    } else if (err.code === 'ER_CON_COUNT_ERROR') {
      console.error('Database has too many connections.');
    } else if (err.code === 'ECONNREFUSED') {
      console.error('Database connection was refused.');
    } else {
      console.error(err.message)
    }
  }

  if (connection) {
    console.log('Connected to the MySQL server.');
    connection.release();
  }
});

module.exports = pool;

I want to connect MySQL with nodejs app I config mysql with nodejs server but when I run my server I got Error: Unknown database <db name> and I have two files in my project databaseConfig.sql and seed.sql how do I use these files in my nodejs app?

mySQL config to nodejs -

const mysql = require('mysql2');

// environment variable config
const dotenv = require('dotenv');
dotenv.config();

const pool = mysql.createPool({
  connectionLimit: 10,
  host: process.env.HOST,
  user: process.env.USER,
  password: process.env.PASSWORD,
  database: process.env.DATABASE,
  multipleStatements: true,
});

// Ping database to check for common exception errors.
pool.getConnection((err, connection) => {
  if (err) {
    if (err.code === 'PROTOCOL_CONNECTION_LOST') {
      console.error('Database connection was closed.');
    } else if (err.code === 'ER_CON_COUNT_ERROR') {
      console.error('Database has too many connections.');
    } else if (err.code === 'ECONNREFUSED') {
      console.error('Database connection was refused.');
    } else {
      console.error(err.message)
    }
  }

  if (connection) {
    console.log('Connected to the MySQL server.');
    connection.release();
  }
});

module.exports = pool;

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.