简体   繁体   English

如何使用nodejs和pem keyfile连接到Cloud SQL实例

[英]How to connect to Cloud SQL instance using nodejs and pem keyfile

I'm trying to connect to Cloud SQL instance from nodejs application using pem file key. 我正在尝试使用pem文件密钥从nodejs应用程序连接到Cloud SQL实例。

var fs = require('fs');
var Sequelize = require('sequelize');

var sequelize = new Sequelize('database', 'root', '', {
    host: '<ip>',
    dialect: 'mysql',
    ssl: {
       ca: fs.readFileSync(__dirname + '/server-ca.pem'),
       key: fs.readFileSync(__dirname + '/cert.pem')
    }
});
sequelize.query('select * from Users').then(function (users) {
    console.log(users);
});

I got Possibly unhandled SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'<ip>' (using password: NO) . Possibly unhandled SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'<ip>' (using password: NO)

What am I doing wrong? 我究竟做错了什么?

It looks like your ssl options are not correct. 看起来您的ssl选项不正确。 You have put a "cert" file in the key parameter. 您已在key参数中放置了“cert”文件。 Your ssl config should look like: 您的ssl配置应如下所示:

  ssl: {
     ca: fs.readFileSync(__dirname + '/server-ca.pem'),
     cert: fs.readFileSync(__dirname + '/client-cert.pem'),
     key: fs.readFileSync(__dirname + '/client-key.pem')
  }

Where client-key.pem is the private key corresponding to client-cert.pem. 其中client-key.pem是与client-cert.pem对应的私钥。 You should get all three of these files when you follow the Cloud SQL SSL instructions . 当您遵循Cloud SQL SSL说明时,您应该获得所有这三个文件。

I just looked up a quick google search of mysql access denied using password no , and the MySQL docs themselves say that this error message comes when you tried to log in without using a password. 我只是查了一个快速谷歌搜索mysql access denied using password no ,并且MySQL文档自己说当你尝试不使用密码登录时出现此错误消息。 (CTRL + F for "you tried to log in without a password"). (CTRL + F表示“您试图在没有密码的情况下登录”)。 This is likely to be the source of the issue. 这很可能是问题的根源。

Otherwise, have you followed the instructions from the Cloud SQL docs on how to connect from an external application ? 否则,您是否按照Cloud SQL文档中有关如何从外部应用程序进行连接的说明进行操作 Specifically, you'll want to ensure that your box's IP or IP range is allowed by your instance. 具体而言,您需要确保实例允许您的盒子的IP或IP范围。 Be aware that if you're behind a firewall that does NAT, a corporate proxy, an open proxy, or any other private proxy you/your ISP owns, you'll need to ensure that the IP of that network node is allowed, as your IP packets will appear to originate from there. 请注意,如果您位于执行NAT,公司代理,开放代理或您/ ISP所拥有的任何其他私人代理的防火墙后面,则需要确保允许网络节点的IP,如您的IP数据包似乎来自那里。 You can test this by running dig +short myip.opendns.com @resolver1.opendns.com , which will use an external service to tell you what your IP appears to be. 您可以通过运行dig +short myip.opendns.com @resolver1.opendns.com来测试这一点,它将使用外部服务告诉您IP看起来是什么。

You may also want to double-check the docs on TLS and Cloud SQL to ensure everything you've done is good in that regard. 您可能还需要仔细检查TLS和Cloud SQL上的文档,以确保您在这方面所做的一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将云SQL实例连接到SQL群集? - how to connect a cloud sql instance to an sql cluster? Google App Engine-使用mysqli用php连接到SQL Cloud实例 - Google App Engine - Connect to SQL Cloud Instance with php using mysqli 如何使用App Engine从Eclipse连接到Google Cloud SQL实例? - How to connect to google cloud sql instance from eclipse using App Engine? 如何从外部PHPMyAdmin安装连接到Google Cloud SQL实例? - How to connect to a Google cloud SQL instance from an external PHPMyAdmin installation? 如何从其他服务器连接到Google Cloud SQL实例 - How to Connect to a Google Cloud SQL Instance from a Different Server Google Cloud - 无法使用内部 IP 从 GKE 连接到 MySQL 云 sql 实例 - Google Cloud - Cant connect to MySQL cloud sql instance from GKE using internal IP 无法连接 GCP 云 SQL 私有实例 - Unable to connect to GCP cloud SQL private instance 从本地运行的 NodeJS / TypeORM 连接到 Google Cloud MySQL 实例 - Connect to Google Cloud MySQL instance from local running NodeJS / TypeORM 从 Google AppEngine Standard 连接到 Google Cloud SQL 实例时出错(使用 NodeJS) - Error connecting from Google AppEngine Standard to Google Cloud SQL instance (Using NodeJS) 使用IP连接到Cloud SQL - Connect to Cloud SQL using IP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM