Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

mysql - 使用节点连接到远程mysql数据库(connection to a remote mysql database using node)

Good mornig to you guys.

(祝大家好。)

I want to establish a connection to a remote mysql database using node js.

(我想使用节点js建立到远程mysql数据库的连接。)

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.

(错误:GetaddrInfoReqWrap.onlookup上的getaddrinfo ENOTFOUND http://kamerun-it.com/mysql [完整完成](dns.js:60:26)------------------ -在Protocol._enqueue(F:\ kamerun it \ aspi-api \ node_modules \ mysql \ lib \ protocol \ Protocol.js:144:48)在Protocol.handshake(F:\ kamerun it \ aspi-api \ node_modules \在PoolConnection.connect(F:\ kamerun it \ aspi-api \ node_modules \ mysql \ lib \ Connection.js:119:18)在Pool.getConnection(F:的mysql \ lib \ protocol \ Protocol.js:51:23) \ kamerun it \ aspi-api \ node_modules \ mysql \ lib \ Pool.js:48:16)。)

(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 }

((F:\ kamerun it \ aspi-api \ app \ model \ db.js:16:8)位于Object.Module._extensions的Module._compile(internal / modules / cjs / loader.js:956:30)。在Function.Module._load(内部/模块/ cjs / loader)的Module.load(内部/模块/cjs/loader.js:812:32)的js(内部/模块/cjs/loader.js:973:10)。 js:724:14)在Module.require(internal / modules / cjs / loader.js:849:19){errno:'ENOTFOUND',代码:'ENOTFOUND',syscall:'getaddrinfo',主机名:' http:/ /kamerun-it.com/mysql ',致命:true})

  ask by NGOUNE ALBAN translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(您的主机URL配置中可能存在错误。)

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

(这是一个与远程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.

(第二个返回相同的ENOTFOUND错误。)

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

(检查这是否是正确的URL,是否可以远程访问数据库以及可以通过哪个端口使用它。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...