0

I'm trying to deploy my express server on Heroku which needs to connect to the remote MySQL database.

I used 'heroku config:add DATABASE_URL=mysql://dbusername:dbpassword@databasehostIP:databaseserverport/databasename with the correct information but still it tries to connect through wrong address.

I also used 'heroku config:add EXTERNAL_DATABASE_URL=mysql://dbusername:dbpassword@databasehostIP:databaseserverport/databasename with the correct information but still it tries to connect through wrong address.

In my Heroku app panel under 'setting' in 'Config Vars' section I see that DATABASE_URL and EXTERNAL_DATABASE_URL appeared with correct information. but in heroku log I still see the wrong information

This is my sequelize variable on the express server:

const sequelize = new Sequelize('dbName', 'USER', 'Password', {
host:"hostAddress",
dialect: 'mysql'

}

But I see the following on Heroku log:

2019-02-16T18:31:42.231390+00:00 app[web.1]: Unhandled rejection 
SequelizeAccessDeniedError: Access denied for user 
'USER'@'ec2-54-162-8-141.compute-1.amazonaws.com' (using 
password: YES)

How can I change 'ec2-54-162-8-141.compute-1.amazonaws.com' to the remote MySQL host address?

  • 1
    Please check the server ec2-54-162-8-141.compute-1.amazonaws.com port - 3306 is opened or not also the user - USER is present in the DB server – Rohit Dalal Feb 17 '19 at 13:34

1 Answers1

0

Try setting your variable with something like this:

if (process.env.DATABASE_URL) {
  const sequelize = new Sequelize(process.env.DATABASE_URL, {
    define: {
      freezeTableName: true, // don't make plural table names
      underscored: true // don't use camel case
    },
    dialect: 'mysql',
    dialectOptions: {
      ssl: true
    },
    logging: true,
    protocol: 'mysql',
    quoteIdentifiers: false // set case-insensitive
  });
} else {
  console.log('Fatal error: DATABASE_URL not set');
  process.exit(1);
}
davejagoda
  • 2,420
  • 1
  • 20
  • 27
  • Thank you for your response but the issue still exist – pouyan zarbafian Feb 17 '19 at 15:35
  • Does `heroku config:get DATABASE_URL` show the database you are trying to use? – davejagoda Feb 17 '19 at 15:40
  • Is the hostname contained in that `DATABASE_URL` either `ec2-54-162-8-141.compute-1.amazonaws.com` or `54.162.8.141`? – davejagoda Feb 17 '19 at 18:43
  • no. this is what I get when run heroku config:get DATABASE_URL heroku config:get DATABASE_URL -a qfpfinder » Warning: heroku update available from 7.19.3 to 7.20.1 mysql://quickfit_adminFinder@quickfitparts.com:3306/quickfit_finder – pouyan zarbafian Feb 18 '19 at 02:25
  • The DATABASE_URL should be like this: `mysql://user:password@hostname:port/dbname`. Your URL appears to lack a : between the username and password. Are you able to connect to that database from the Internet? I also don't understand where that ec2 host is coming from. Can you try `heroku config | grep ec2`? Also, is it possible there is more than one heroku instance, and you are looking at one while using another? Lastly, you might want to change your password if you've posted any part of it here. – davejagoda Feb 18 '19 at 05:18
  • how should I try `heroku config | grep ec2` ? – pouyan zarbafian Feb 18 '19 at 14:40
  • like this: ` heroku config -a qfpfinder | grep -i ec2` (similar to how you did it when got the DATABASE_URL earlier) – davejagoda Feb 18 '19 at 18:48
  • It returns DATABASE_URL: `mysql://quickfit_adminFinder@quickfitparts.com:3306/quickfit_finde` and nothing related to `ec2-54-162-8-141.compute-1.amazonaws.com` – pouyan zarbafian Feb 20 '19 at 00:11