Home > OS >  how to connect nodejs sequelize aws rds mysql database and ec2 instances
how to connect nodejs sequelize aws rds mysql database and ec2 instances

Time:09-21

I'm trying to connect my EC2 instance and AWS RDS MySQL database. Ii returns the database not found an error.

How can I fix git fix?

RDS database successfully connect with my MySQL workbench

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname   '/../config/config.json')[env];
const db = {};

let sequelize;
if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
  sequelize = new Sequelize('*db name*', '***username***', '****pwd*****', {
    host: '*********.us-east-2.rds.amazonaws.com',
    port: 3306
    logging: console.log,
    maxConcurrentQueries: 100,
    dialect: 'mysql',
    dialectOptions: {
        ssl:'Amazon RDS'
    },
    pool: { maxConnections: 5, maxIdleTime: 30},
    language: 'en'
});
}

db.Sequelize = Sequelize;
db.sequelize = sequelize;

module.exports = db;

I'm using

  • sequelize version ^6.6.4
  • Nodejs version 14.15.1

Screenshot of the error.

screenshot

CodePudding user response:

As per screenshot, you are trying to connect to the DB using it's DB name.

But there is a little confusion between AWS RDS DB Instance name and MySQL default DB name is mysql.

So, I'd suggest to use mysql instead of AWS-tvrs as DB name.

  • Related