我无法连接 mysql 数据库。当我多次尝试启动 Node 服务器时,它会抛出数据库连接错误。
错误是:-
connect ETIMEDOUT
at Connection._handleConnectTimeout
最佳答案
使用以下内容创建文件 mysql_yourname:
const mysql = require('mysql');
const conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "pass",
database: "databaase"
});
conn.connect(function(err) {
if(err) throw "There is no connection to the mysql server..." + err.message;
console.info("Connected!");
});
exports.conn = conn;
然后在您的代码中需要该模块,您就会连接。
Connected!
关于javascript - Node 服务器无法连接mysql数据库connect ETIMEDOUT at Connection._handleConnectTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44106202/