我想要的Node.js和MySQL,但即時收到此錯誤:服務器關閉了連接
:Error: Connection lost: The server closed the connection. my code here.
var mysql = require('mysql');
var config = {
connectionLimit: 100,
waitForConnections: true,
queueLimit: 0,
debug: true,
wait_timeout: 28800,
connect_timeout: 10,
host: "localhost",
user: " root ",
password: " root ",
database: "mydb"
};
var table = 'mytable';
var connection;
function handleConnection() {
connection = mysql.createConnection(config);
connection.connect(function(err) {
console.log("connected");
});
connection.query('select * from' + table,
function(err, result, fields) {
if (!err) {
console.log("result :" + result);
} else {
console.log("error1 :" + err);
}
});
}
請縮進代碼。 –
什麼是wait_timeout ..? 以及爲什麼你沒有寫connectTimeout而不是connect_timeout ..? – vkstack