I am trying to connect to my Amazon RDS cloud database using Express framework. My server.js connection looks as follows:
const express = require('express');
var bodyParser = require('body-parser')
const mysql = require('mysql');
const cors = require('cors');
const port = process.env.PORT || 3300;
const connection = mysql.createConnection({
host : 'endpoint-of-my-rds-database.amazonaws.com',
user : 'user',
password : 'password',
database : 'database',
port: 3300,
socketPath: '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'
});
const app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
connection.connect(function(err) {
if(err) throw err;
console.log("connected to database");
})
After running node server.js I get the following standard error:
Access denied for user 'root'@'localhost' (using password: YES)
I am able to connect to my cloud database with the same credentials using MySQL Workbench. Also, I can connect to my local MySQL database through Express by changing credentials to those of my local MySQL database.
Researching online, it appears that this error is due to invalid credential, but, as I've mentioned, I can connect to my RDS database through Workbench with no issues. It is only Express that seems to give me trouble. Will be happy to provide additional info. Any help will be appreciated. Thank you in advance.
server.jswithout starting my local MySQL server I get an error:Error: connect ENOENT /Applications/XAMPP/xamppfiles/var/mysql/mysql.sockIt seems that it attempts to connect to RDS database only if I run local MySQL server. Or I am completely misunderstanding it.