0

How can I prevent my finished queries to stay in pool?

Below is the image of my database and a lot of my finished queries are staying and I want them to be removed but don't know how.

database image

This is my code that I made to sent the data from my database using Express:

Here is my articles.js file that sends the data as json.

router.get('/articles', (req, res) => {
  let sql = "SELECT * FROM ARTICLES";
  myDB.query(sql, (error, results) => {
    if (error) {
      console.log(error);
    } else {
      res.send(results)
    }
  })
});

and this is my connection.js that creates the connection to MySQL and Express

    const mysql = require('mysql');
const myDB = mysql.createPool({
    connectionLimit: 10,
    host: 'REMOTE_DATABASE_ADDRESS',
    user: 'hmidev',
    password: 'hmidev',
    database: 'VD_NEW_WEBSITE'
});

myDB.getConnection((error, connection) => {
    if (error) {
        console.log(error);
    } else {
        console.log(`Successfully connected at VD_NEW_WEBSITE`);
    }
});

module.exports = myDB;
  • myDB.end();? Look stackoverflow.com/q/27386205/10138734 and similar – Akina Oct 17 at 7:49
  • nope, it doesn't do what I want, it just kills the connection instantly – learn2code Oct 17 at 8:07
  • Connection is killed, but last query result is available nevertheless? – Akina Oct 17 at 8:44
  • No it is not it kills the whole connection – learn2code Oct 17 at 8:51
  • If so try to execute some "empty" query (SELECT 1; for example, or SELECT VERSION();) - maybe it will override previous recordset? and add proper tag(s) (maybe [node.js] ?) to your question. – Akina Oct 17 at 9:32
0

Connections left in a connection pool will show up as "Sleep" in PROCESSLIST. The "Time" will continue to grow until grabbed by a new "connect".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.