1

Good mornig to you guys. I want to establish a connection to a remote mysql database using node js. but i am facing this error. I do not know if I wrongly specifies the access path to the db

code

var mysql = require('mysql');

var pool = mysql.createPool({
  host: "http://kamerun-it.com/mysql",
  connectionLimit : 100,
  database: "****",
  user: "****",
  password: "*****",
  multipleStatements: true

});

error

  throw err;
  ^

Error: getaddrinfo ENOTFOUND http://kamerun-it.com/mysql at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) -------------------- at Protocol._enqueue (F:\kamerun it\aspi-api\node_modules\mysql\lib\protocol\Protocol.js:144:48) at Protocol.handshake (F:\kamerun it\aspi-api\node_modules\mysql\lib\protocol\Protocol.js:51:23) at PoolConnection.connect (F:\kamerun it\aspi-api\node_modules\mysql\lib\Connection.js:119:18) at Pool.getConnection (F:\kamerun it\aspi-api\node_modules\mysql\lib\Pool.js:48:16) at Object. (F:\kamerun it\aspi-api\app\model\db.js:16:8) at Module._compile (internal/modules/cjs/loader.js:956:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Module.require (internal/modules/cjs/loader.js:849:19) { errno: 'ENOTFOUND', code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'http://kamerun-it.com/mysql', fatal: true }

1 Answer 1

1

You probably have an error in your config with the host URL.

Here's a working example with a connection to a remote MySQL:

const mysql = require("mysql");

const connection = mysql.createPool({
  host: "remotemysql.com",
  user: "aKlLAqAfXH",
  password: "PZKuFVGRQD",
  database: "aKlLAqAfXH"
});

connection.query(
  "SELECT hexcode FROM colours WHERE precedence = 2",
  (err, result) => {
    err ? console.log(err) : console.log(result[0].hexcode);
  }
);

and here's one with mistaken host parameter:

const mysql = require("mysql");

const connection = mysql.createPool({
  host: "WRONGremotemysql.com",
  user: "aKlLAqAfXH",
  password: "PZKuFVGRQD",
  database: "aKlLAqAfXH"
});

connection.query(
  "SELECT hexcode FROM colours WHERE precedence = 2",
  (err, result) => {
    err ? console.log(err) : console.log(result[0].hexcode);
  }
);

The second one returns the same ENOTFOUND error.

Check if that's the correct URL, if the database can be accessed remotely and via which port you can use it.

Sign up to request clarification or add additional context in comments.

4 Comments

when i am going to the host url kamerun-it.com/mysql,I can access my database by entering credentials ( **is ok to confirm that the url is correct and the database can be accessed remotely ?? **)
you access phpmyadmin portal which is running on web port 80, remote access to a db is different. No, it's correct to say it can be accessed remotely.
remote access is different?? how to access this database in my case
if you want to use it via script that's not on the same server - that's remote access. It should be allowed/configured by your hosting provider or sysadmin or you enable it if you have access to mysql configs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.