I have such nodejs code:
var mysql = require('mysql2/promise');
mysql.createConnection({
host: "localhost",
user: "root",
password: "123123",
database: "mydatabase"
})
.then((connection) => connection.execute("SELECT * FROM mytable"))
.then(([rows, fields]) => {
console.log(rows);
});
When I execute it, application prints array of database rows and is still running after that. Seems it happens because connection isn't released. How to release it after console.log
?
I've tried this way:
var mysql = require('mysql2/promise');
mysql.createConnection({
host: "localhost",
user: "root",
password: "123123",
database: "mydatabase"
})
.then((connection) => {
connection.execute("SELECT * FROM mytable")
.then(([rows, fields]) => {
console.log(rows);
connection.release();
});
});
but result is TypeError: this.connection.release is not a function
.
Sorry for my English.
Any ideas?
I have such nodejs code:
var mysql = require('mysql2/promise');
mysql.createConnection({
host: "localhost",
user: "root",
password: "123123",
database: "mydatabase"
})
.then((connection) => connection.execute("SELECT * FROM mytable"))
.then(([rows, fields]) => {
console.log(rows);
});
When I execute it, application prints array of database rows and is still running after that. Seems it happens because connection isn't released. How to release it after console.log
?
I've tried this way:
var mysql = require('mysql2/promise');
mysql.createConnection({
host: "localhost",
user: "root",
password: "123123",
database: "mydatabase"
})
.then((connection) => {
connection.execute("SELECT * FROM mytable")
.then(([rows, fields]) => {
console.log(rows);
connection.release();
});
});
but result is TypeError: this.connection.release is not a function
.
Sorry for my English.
Any ideas?
Share asked Feb 1, 2017 at 18:24 lem0nifylem0nify 7931 gold badge6 silver badges16 bronze badges 1-
I don't think
release
is the correct function name. The reference documentation implies it'send
ordestroy
. – tadman Commented Feb 1, 2017 at 18:26
1 Answer
Reset to default 10Since mysql2
mostly keeps API patibility with mysql
, you should be able to close the connection with connection.end()
.