简体   繁体   English

连接超时:Nodejs Google App Engine到Cloud MySql

[英]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.

相关问题 Google Cloud SQL与Google App Engine之间的连接-超时 - Connection between Google Cloud SQL and Google App Engine - Time out 与mysql的连接超时 - Connection to mysql timed out Google App引擎和Cloud SQL连接被拒绝 - Google App engine and Cloud sql connection refused NodeJ:无法从Google App Engine连接Google Cloud SQL - NodeJs:Unable to connect Google Cloud SQL from Google App Engine Google App Engine和Cloud SQL:在“读取初始通信数据包”时丢失与MySQL服务器的连接 - Google App Engine and Cloud SQL: Lost connection to MySQL server at 'reading initial communication packet' 生产中Google App Engine和Google Cloud SQL的连接出现问题 - Issue with connection from Google App Engine and Google Cloud SQL on production Google App Engine 应用程序连接到第三方云 - Google App Engine application connection to a Third Party Cloud 是否可以将JPA连接池与Google App Engine和Cloud SQL一起使用? - Is it possible to use a JPA connection pool with Google App Engine and Cloud SQL? Google App Engine 上的 Django 连接到云 SQL,无法连接 - Django on Google App Engine connection to Cloud SQL, cannot connect 无法使用Google App Engine连接到Google Cloud MySQL - Unable to Connect to Google Cloud MySQL using Google App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM