mysql.connect永远不会返回

mysql.connect永远不会返回,mysql,node.js,Mysql,Node.js,当我运行它时,我会看到“Connected to DB”日志,但程序从未完成或退出,就像它在等待什么一样。让我们尝试获取下面的代码,并将其保存到“dbConnect.js”文件中,然后运行node命令: >节点dbConnect.js 你会看到结果的 const mysql = require('mysql'); const dbCon = mysql.createConnection({ host: "localhost", user: "mainUser", pas

当我运行它时,我会看到“Connected to DB”日志,但程序从未完成或退出,就像它在等待什么一样。

让我们尝试获取下面的代码,并将其保存到“dbConnect.js”文件中,然后运行node命令:
>节点dbConnect.js
你会看到结果的

const mysql = require('mysql');

const dbCon = mysql.createConnection({
    host: "localhost",
    user: "mainUser",
    password: "pa55",
    database: "testDB"
});

dbCon.connect(function (err) {
    if (err) throw err;
    console.log("Connected to DB");
});

让我们尝试获取下面的代码,并将其保存到“dbConnect.js”文件中,然后运行node命令:
>节点dbConnect.js
你会看到结果的

const mysql = require('mysql');

const dbCon = mysql.createConnection({
    host: "localhost",
    user: "mainUser",
    password: "pa55",
    database: "testDB"
});

dbCon.connect(function (err) {
    if (err) throw err;
    console.log("Connected to DB");
});