3

I would like to connect my 1and1 mySQL Database on an Express App Node.JS with the mysql npm package but when I tried to connect the console send me back this:

Error: getaddrinfo ENOTFOUND <DB_HOST_NAME>

I looked on the 1and1 dashboard and it was the good logs, I tried to put 'tcp:\\' and ':3306' but no results, node can't find the database. Moreover the first website version was in PHP and the logs was working and still working with PHP so the logs are correct. I asked the 1and1 service but no answer.

I looked for survey on this error but anybody was able to find an answer.

Few snippets:

// Import Modules
const EXPRESS = require('express');
const CORS = require('cors');
const MYSQL = require('mysql');

// Import Database Configuration
const DB_CONFIG = require('./config/DbConfiguration');

// Create Express App Instance
const APP = EXPRESS()
APP.use(CORS())

// Server Port Const
const SERVER_PORT = 4000

// Create MySQL Connection Instance
const CONNECTION = MYSQL.createConnection(DB_CONFIG.dbConfiguration);
CONNECTION.connect(function(err) {

    // Print Error 
    if(err) {console.error(err)};

});

DbConfiguration.js

require('dotenv/config')

module.exports = {

    dbConfiguration: {
        host: process.env.DB_HOST,
        user: process.env.DB_USER,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_NAME
    }
}

.ENV file

DB_HOST=xxxxx.1and1.fr
DB_USER=xxxxxxx  
DB_PASSWORD=xxxxxx
DB_NAME=xxxxxxx  
Shadow
  • 33,525
  • 10
  • 51
  • 64
Gregoirelpv
  • 92
  • 1
  • 10
  • check with the permission of the database host `ENOTFOUND ` error occurs when the host is not accessible from your IP – aRvi Sep 12 '20 at 14:07

2 Answers2

1

Have been looking at this problem myself recently too. Due to the way in which 1&1 IONOS manage security to their mySQL servers, you're only able to connect to them using your account (workspace). Further information on this is accessible via their website. Unfortunately, you either need to deploy your code to your workspace or use an alternative local phpMyAdmin installation for development. Not ideal I know!

0

change your configuration of a connection string like if you are running on local machine try

`host:'localhost' or host:'127.0.0.1`

wrap it in string.

Haker Baya
  • 56
  • 5
  • I'm not sur that the problem come from my config, I tested it and the console send me back ```Error: connect ECONNREFUSED 127.0.0.1``` – Gregoirelpv Sep 05 '20 at 18:05
  • It will refuse, because you are not mentioning port number in configuration. Try like add another key to configuration `port: 'your-db-portnumber'` or it will not work then change your host to `host: 'your-db-host-name:portnumber'` – Haker Baya Sep 06 '20 at 10:20
  • Same problem ```Error: getaddrinfo ENOTFOUND xxxxxxxx:3306``` and same with xxxxxxx-3306, I tried with my localhost db and it was working so I think it come from IONOS 1and1 – Gregoirelpv Sep 06 '20 at 13:41