【问题标题】:Cloud Function not connecting with Cloud SQLCloud Function 未与 Cloud SQL 连接
【发布时间】:2018-05-30 22:25:45
【问题描述】:

这是我的节点 js 代码

var mysql = require('mysql');

exports.helloGET = (req, res) => {

console.log(req.body.message);

var con = mysql.createConnection({
      //socketPath: '/cloudsql/' + 'project-id:region-name:instance',
      host: 'xxx.xxx.xxx.xxx',
      user: 'user',
      password: 'root',
      database: 'test'
    });

    con.connect(function(err) {
        console.log("Connection Error - " + err)
        if (err) throw err;
        console.log("Connected to Cloud SQL");
    });

    con.query(`SELECT now()`, null, function (err, result) {
        //made reply here
        console.log("Query Error - " + err)
        if (err) throw err;
        console.log("Result: " + result);
    });

con.end();
res.status(200).send('Acknowledgement : ' + req.body.message);
};

错误:连接 ETIMEDOUT xxx.xxx.xxx.xxx:3306

我尝试使用 socketPath 而不是主机 -

var con = mysql.createConnection({
      socketPath: '/cloudsql/' + 'project-id:region-name:instance',
      //host: 'xxx.xxx.xxx.xxx',
      user: 'user',
      password: 'root',
      database: 'test'
    });

为此我得到 - 错误:连接 ECONNREFUSED

【问题讨论】:

    标签: google-cloud-functions google-cloud-sql


    【解决方案1】:

    目前不支持该功能。但是,您可以在问题跟踪器#36388165 中关注一个功能请求。

    就像 Jason Polites 在 this comment 中提到的那样,您可以填写此早期访问表单,以便从 Cloud Function 访问 Cloud SQL。

    【讨论】:

      猜你喜欢
      • 2019-05-26
      • 2020-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-02
      • 2019-10-28
      • 2020-06-15
      • 1970-01-01
      相关资源
      最近更新 更多