scene
I link to the database in three ways:
- first: use
.connect ()
.end ()
. Continuous requests can be made for the first time, and then there will be ups and downs- second: do not use
.connect ()
.end ()
. Continuous requests. All requests are normal. reference there is a sentence in the document that However, a connection can also be implicitly established (implicitly links to) by invoking a query.. Why is the implicit link ok??- third: use link pooling
mysql.createPool ()
. Continuous requests. All requests are normal
looked up all kinds of materials and encountered the same problem on GitHub. issues knows how to ok, with connection pooling and implicit links, but still wants to figure it out. And how to use the first .connect ()
.end ()
to achieve consecutive requests without reporting errors
var mysql = require("mysql");
// .connect() .end()
var connection = mysql.createConnection({
//
})
...
connection.connect()
connection.query(sql, function (error, results, fields) {
//
})
connection.end()
...
// .connect() .end()
var connection = mysql.createConnection({
//
})
...
connection.query(sql, function (error, results, fields) {
//
})
...
//
var pool = mysql.createPool({
//
})
...
pool.getConnection(function (err, connection) {
connection.query(sql, function (error, results, fields) {
connection.release();
//
})
});
...