1
votes

I have a Node.js app (running on AppEngine) connecting to a GCP CloudSQL (MySQL) instance. Now I want to connect to the same database from Node.js (Knex) running on Heroku.

From AppEngine, Node.js connects via user/password and socketPath. I'm also connecting to the same MySQL DB from MySQL Workbench via host IP (over SSL).

I'm trying to use the same host, port, user and pass as Workbench from Heroku and it's not working. To try and make it easy, I've temporarily allowed all networks to connect (0.0.0.0/0) and I've allowed non-SSL connections.

Here's the error: ER_ACCESS_DENIED_ERROR: Access denied for user 'usernamehere'@'xx.xxx.xxx.xx' (using password: YES)"

The environment variables are stored in the Heroku app and they must be working because the username is correct.

It's not very helpful, but here's the code:

import Knex = require('knex');
const envConfig = require('../config/environments').get(process.env.NODE_ENV);
module.exports = knex;
1
the error message you are getting is a MySQL please verify that you connection information is fine. here the same issue was happening and there are some workarounds - Soni Sol
@JoséSoní no, unfortunately not. I've worked through those suggestions and the problem is still happening with a new user, new pass, and npm package update. - beachCode
how are you connecting to cloudSQl, and could you share if you are getting logs on cloudSQL side? - Soni Sol

1 Answers

1
votes

The only way I found to resolve this issue was to connect to CloudSQL over SSL.

const mysql = require("mysql");
const fs = require('fs');
const knex = require('knex')({
    client: 'mysql',
    version: '5.7',
    connection: {
      host : 'xx.xx.xx.xx',
      ssl: {
        ca: fs.readFileSync('ca.pem'),
        key: fs.readFileSync('client-key.pem'),
        cert: fs.readFileSync('client-cert.pem'),
      },
      user : 'root',
      password : 'xxxxxxxxx',
      database : 'mydbname',
    },
});