Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!