简体   繁体   中英

About MySQL module in node.js and concurrent connections to mySQL Database

I am planning to deploy an Angular website with node.js backend and mySQL database to a shared hosting that support it. The hosting website has a limit of maximum 25 concurrent connections to mySQL database at a time.

I am using mySQL module in node.js to access the database. Here is a pseudo-code that represents the structure:

const mysql = require('mysql');

app.get('/query/:id', function (req, res) {
    let mc = mysql.createConnection(...);
    mc.connect((err)=>{
       ...
       mc.query(...);}
    );});

Now what I am not sure about is: If the maximum concurrent connection limit to the database is reached, where will the error generate? Will the error come from this step:

mysql.createConnection()

, or this step:

mc.connect()

,or this step:

mc.query()

Also, where is the most appropriate place to deal with the error?

Based on the documentation for error handling: https://github.com/mysqljs/mysql#error-handling

You would see an error in both the mc.connect() and mc.query callbacks, however in your case above it probably wouldn't make it to the mc.query since that is inside of the mc.connect callback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM