我无法连接mysql数据库。当我尝试启动节点服务器很多次时,它引发数据库连接错误。

错误是:-

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!

10-07 19:09
查看更多