Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize Connect ETIMEOUT when connecting to remote mysql db

I am getting error SequelizeConnectionError: connect ETIMEDOUT when trying to connect to a remote mysql db with sequelize.

Connection can be established successfully when I try to connect to my local mysql db.

I'm using sequelize's default db connection code new Sequelize(...) contained within models/index.js, with the following config (filled up with the correct values):

"production": {
  "username": "root",
  "password": null,
  "database": "database_production",
  "host": "127.0.0.1",
  "dialect": "mysql"
} 

I tried connecting to the remote db with a simple php script and it worked (so we can rule out issues on the remote db server side)

Any ideas?

like image 585
artze Avatar asked Jun 23 '17 05:06

artze


2 Answers

For me, I have to:

1) Define exact information of my database at the local server (Xamp/ Mamp). It means I must have the existing database to connect, user name and password is a privileged account in your database.

2) Xamp/ Mamp must be online (of course). Default ports will be taken by this local server, so try a different port for mysql 8889 instead of 3306.

And this is what I tried:

sequelize = new Sequelize('wohui', 'root', 'root', {
  dialect: 'mysql',
  host: 'localhost',
  port: 8889
});

sequelize
        .authenticate()
        .then(() => {
            console.log('Connection has been established successfully.');
        })
        .catch((err) => {
            console.log('Unable to connect to the database:', err);
        });
like image 82
Nguyen Tan Dat Avatar answered Sep 17 '22 11:09

Nguyen Tan Dat


This error usually appears when the connection to the sql server is not established. Some things to take care of are :

  1. Ensure mysql server is running in the host you are trying to connect to.
  2. Ensure the host ip is correct.
  3. Ensure that the port entered is correct.
  4. Ensure that the firewall rules are defined correctly.
like image 37
Nithin K Avatar answered Sep 20 '22 11:09

Nithin K