当我启动以下示例代码时,它第一次正常运行。但是,如果您在1分钟后重新启动,则会在5毫秒后显示“连接错误”。
两个奇怪的事情是:
代码:
const mysql = require('mysql');
const mysqlConfig = {
connectionLimit: 1,
user: 'root',
password: 'xxxxx',
database: 'mydb',
socketPath: '/cloudsql/myproject:europe-west1:exampledb'
};
exports.sqldemo = (req, res) => {
mysqlPool = mysql.createPool(mysqlConfig);
mysqlPool.query('SELECT * FROM entries', (err, results) => {
mysqlPool.end();
if (err) {
res.send(err);
} else {
res.send(results);
}
});
}
package.json包含:
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"mysql": "2.16.0"
}
}