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,是否可以远程访问数据库以及可以通过哪个端口使用它。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…