How to connect to Cloud SQL instance using nodejs and pem keyfile

I am trying to connect to a Cloud SQL instance from a nodejs application using the pem file key.

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 have received Possibly unhandled SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'<ip>' (using password: NO).

What am I doing wrong?

+4
source share
2 answers

It looks like your ssl options are wrong. You put the "cert" file in the parameter key. Your ssl configuration should look like this:

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

If client-key.pem is the private key corresponding to client-cert.pem. You should get all three of these files by following Cloud SQL SSL instructions .

+2
source

Google mysql access denied using password no, MySQL , , , . (CTRL + F " " ). , .

Cloud SQL ? , , IP- IP- . , , NAT, , , / -, , IP- node , IP- . , dig +short myip.opendns.com @resolver1.opendns.com, , , IP-.

TLS Cloud SQL, , , .

+1

All Articles