Node MySQL error - Error: Cannot enqueue Quit after invoking quit
I'm creating a promise based API. Everything works fine if I make one request at a time, but, if 2 or more requests hit the server within a second of each other, I get the following error
Error: Cannot enqueue Quit after invoking quit
db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
// database: 'my_db'
});
// db.connect = (err) => {
// if (err) throw err;
// console.log('mysql connected');
// };
//创建数据库
app.get('/create', (res, req) => {
let sql = 'CREATE DATABASE nodemysql';
db.query(sql, (err, result) => {
if (err) throw err;
console.log(result);
res.send('Database create')
})
})
// db.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
// if (error) throw error;
// console.log('The solution is: ', results[0].solution);
// });
// db.end();
If you using the node-mysql module, just remove the .connect and .end. Just solved the problem myself. Apparently they pushed in unnecessary code in their last iteration that is also bugged. You don't need to connect if you have already ran the createConnection call
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭