【问题标题】:Synch implementation mysql queries in node在节点中同步实现mysql查询
【发布时间】:2019-06-10 08:11:31
【问题描述】:

使用mysql2

真的吗,如果我们将connectionLimit设置为1,那么mysql查询将被串行执行(而不是并行)?

例如:

const mysql = require('mysql2');

const pool = mysql.createPool({
  host: 'localhost',
  user: 'name',
  password:'password',
  database: 'database',
  waitForConnections: true,
  connectionLimit: 1,
  queueLimit: 0
}).promise();


pool.query("SELECT 'long' as query_result FROM table where big_column like '%sometext%'").then(r=>{ console.log(r[0])}); // long query
pool.query("SELECT 'fast' as query_result").then(r=>{console.log(r[0])}); // fast query

// Result:
// [ TextRow { query_result: 'long'} ]
// [ TextRow { query_result: 'fast' } ]

【问题讨论】:

    标签: node.js mysql2


    【解决方案1】:

    是的,下一个查询将排队,直到上一个查询的连接被释放回池。

    另外,如果你设置 waitForConnections 为 false,下一个查询将返回错误而不是移动到 queued

    【讨论】:

      猜你喜欢
      • 2014-08-05
      • 1970-01-01
      • 2017-06-30
      • 2023-03-28
      • 2017-06-06
      • 2020-11-03
      • 2019-01-20
      • 2020-07-08
      • 1970-01-01
      相关资源
      最近更新 更多