Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
Connection between MariaDB and NodeJS not working

I'm using a vServer from Ionos for a little project. I installed a MariaDB and NodeJS. Currently I'm trying to connect them both. Here is my code:

const mariadb = require('mariadb');
const pool = mariadb.createPool({
     host: 'localhost', 
     user:'root', 
     password: 'xxxxxxxxx',
     database: 'christmastrees',
     connectionLimit: 5,
});
async function asyncFunction() {
  let conn;
  try {
    conn = await pool.getConnection();
    const rows = await conn.query("SELECT * from bäume");
    console.log(rows); //[ {val: 1}, meta: ... ]
  } catch (err) {
    throw err;
  } finally {
    if (conn) return conn.end();
  }
}

But when executing the file (node app), I get an error message after a few seconds

Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
 From event:
    at _registerHandshakeCmd (/root/server/node_modules/mariadb/lib/connection.js:745:11)
    at /root/server/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/root/server/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/root/server/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/root/server/node_modules/mariadb/lib/pool-base.js:373:9)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true
}

So I searched for help and after 2 hours I literally found only one Idea. I added this line of code to my connection...

port: '/var/run/mysqld/mysqld.sock'

I tryed again to use node app, but this time I didn't get an error message, it is loading forever and nothing happens.

I would be so grateful for any help...

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So I found the solution to my problem.

I checked if my MariaDB Service is even running and no it wasn't ^^

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda