[英]Connection timed out: Nodejs Google App Engine to Cloud MySql
The code is very basic. 该代码非常基础。 Simple nodejs app using mysql.
使用mysql的简单nodejs应用程序。
Error: connect ETIMEDOUT
is received when code tries connecting to Google Cloud MySql server (second generation) on google app engine. Error: connect ETIMEDOUT
当代码尝试连接到Google App Engine上的Google Cloud MySql服务器(第二代)时,收到Error: connect ETIMEDOUT
。
However app is able to connect to MySql server from my local machine since IP
address of my machine is whitelisted. 但是,由于我的计算机的
IP
地址已列入白名单,因此应用程序能够从我的本地计算机连接到MySql服务器。
App engine application and google cloud server belong to same project in google cloud console. App Engine应用程序和Google Cloud Server在Google Cloud Console中属于同一项目。 So no extra permissions are required (?)
因此,不需要额外的权限(?)
So I'm failing to understand how to allow app engine to access MySql server. 因此,我无法理解如何允许应用程序引擎访问MySql服务器。
var express = require('express'),
mysql = require('mysql'),
bodyParser = require('body-parser')
// Application initialization
var connection = mysql.createConnection({
host : 'ip_address',
user : 'root',
password : 'password',
database : 'database_name'
});
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.get('/_ah/health', (req, res) => {
res.status(200)
res.send({hello:'world'})
})
app.get('/', function(req, res) {
connection.query('select * from blogs',
function (err, result) {
if (err) throw err;
res.send({result: result});
}
);
});
// Begin listening
app.listen(8080);
console.log("Express server listening");
Using socketPath param while connecting to mysql helped. 连接到mysql时使用socketPath参数有帮助。
var connection = mysql.createConnection({
host : 'ip_address',
user : 'root',
password : 'password',
database : 'database_name'
socketPath: “/cloudsql/projectName:zone:instance-name”
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.