为什么createPool挂断连接?

时间:2021-04-22 10:11:17

标签: node.js

我的终端挂断了行结果。为什么它不释放连接?我知道我可以使用 end 方法。但 end 方法用于释放所有连接。如何释放当前连接或我不明白如何使用池连接。

const mysql = require('mysql2');

const options =
{
    'host'              : '127.0.0.1',
    'port'              : 3306,
    'user'              : 'pandora',
    'password'          : 'pandora',
    'database'          : 'pandora',
    'supportBigNumbers' : true,
    'waitForConnections': true,
    'connectionLimit'   : 10,
    'queueLimit'        : 10
};

const pool = mysql.createPool(options); 

pool.getConnection(function(err, conn) {
    // Do something with the connection
    conn.query('SELECT * FROM media', (err, rows, fields) => {
        console.log(rows);
    });
    // Don't forget to release the connection when finished!
    pool.releaseConnection(conn);
 })

0 个答案:

没有答案
相关问题