I was able to connect to a remote mysql db with sequelize successfully until yesterday afternoon. I now receive the error SequelizeConnectionError: connect ETIMEDOUT. It just stopped working and we did not release an update or make any changes.
I can also connect to the same database on my localhost without any issues. Also increased the idle and acquire time.
I am using sequelize default database connection code new Sequelize(...) and the following config below:
production": {
"username": "username",
"password": "password",
"database": "database",
"host": "host",
"dialect": "mysql"
}
Any ideas as it worked 100% until yesterday afternoon?
I have already tried to create a new app service and also tried to install a new nodejs app and it still gives the same error.Also increased the idle and acquire time.
Related
I'm running an AWS Lightsail linux instance with Node. I've manually installed MySQL and after some time, have connected successfully from my machine using MySql Workbench. I'm now using Node and Sequelize (local machine) to develop against this remote database. In trying to connect, I'm getting an Access Denied error in Node. Same creds as Workbench but not working.
Wondering if something looks obviously wrong here. I've rechecked the credentials as well. And the AWS instance is at a static IP, so, I'm using that as my connection URL host.
const sequelize = new Sequelize(
process.env.DB_DATABASE,
process.env.DB_USERNAME,
process.env.DB_PASSWORD,
{
host: process.env.DB_HOST, // example 25.13.15.200
dialect: "mysql",
port: 3306,
pool: {
max: 5, // max pool connections
min: 0, // mix pool connections
acquire: 30000, // max time (in ms) that pool will try to get connection before throwing an error
idle: 10000, // max time (in ms) that a connection can be idle before being released
},
operatorAliases: false,
}
);
The error I'm getting in my node server is
Checking database connection...
Unable to connect to the database
Access denied for user 'xxxxxx'#'%' to database 'xxxxxxx' // xxxxxx is to cover actual name
Starting Node / Express server on port 5000
It turned out to be permissions needing to be opened for the account. Was odd however because the connection was successful in workbench but via node/sequelize it didn’t work.
This post helped a lot.
Cannot connect to Database server (mysql workbench)
I am studying react and node js, to build a full stack login authentication page.
Which I found tutorial from this github : "https://github.com/bezkoder/node-js-jwt-auth".
I found this tutorial extremely confusing due to mysql connection errors, the only edit I made is changing the running port from 8080 to 3306, which is a fast fix for having another port running on 8080.
When I run "node server.js" this error pops up few seconds
also, in order to view mysql databases, I am running MySQL Workbench localhost:3306, but the server is stopped, refresh wouldn't work, nor restarting the mysql through services.
The Message shows: Lost connection to MySQL server at 'waiting for initial communication packet'. system error 10060.
Please help, I have no idea what I am doing.
you didn't learn how node.js or react work, so start with much simpler tutorials
port 8080 is the port when you type it in the browser localhost:8080 a webpage appears.
So don't change it, as long as you don't have another page running.
You start by editng
node-js-jwt-auth/app/config/db.config.js
There you find
module.exports = {
HOST: "localhost",
USER: "root",
PASSWORD: "123456",
DB: "testdb",
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
Here you enter the same data as you enter in workbench.
Of course the mysql server has to be installed and running.
I've got two docker services, one running a simple node server and the other a mysql (mariadb actually) database server.
All instances of a socket file mentioned anywhere in /etc/mysql/ say
/var/run/mysqld/mysqld.sock
This will be important soon.
My node server is running some Sequelize code that is trying to connect to the MySQL server.
Whenever I try and connect via Sequelize, I get:
{"statusCode":500,"error":"Internal Server Error","message":"connect ENOENT /var/run/mysqld/mysqld.sock"}
However, if I log into the Node docker container I can successfully connect to MySQL on the other docker container using the mysql CLI client.
I think I understand that the mysql client is using a tcp connection, while Sequelize is using a socket connection. But, when Sequelize is throwing that error, it is showing the correct socket path, as far as I know. Here is my Sequelize config:
const options = {
host: "mysql",
dialect: "mysql",
dialectOptions: {
socketPath: "/var/run/mysqld/mysqld.sock"
}
};
let sequelize = new Sequelize("ibbr_dev", "devuser", "password", options);
The MySQL socket file is not available in your Node container, it is only available in the MySQL container as it is a file. Rather than setting up unix socket based connection, you should use a TCP connection (skipping the dialectOptions).
I have a new azure MySQL server and I am trying to use that with my existing Nodejs app.
When I try to connect to the Mysql instance from my terminal(using mysql command), I am able to successfully connect.
However, We I try to connect through my Nodejs app, which is using sequentialize for ORM, I am unable to connect.
It shows the following error
Unhandled rejection SequelizeConnectionError: ER_HANDSHAKE_ERROR: Bad handshake
Please find my code below
var sequelize = new Sequelize(config.database, config.username, config.password, {
"host": config.host,
"dialect": "mysql",
"dialectOptions": {
"ssl": {ca:fs.readFileSync("./MyCert.crt")},
insecureAuth: true
}
});
FYI: I am using sequelize#2.0.0
kindly help me out in this.
Thanks in advance
Issue fixed in the latest sequelize version(>4.0)
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?
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);
});
I had the same problem, in my case it happened because I forgot to open the connection to mysql port 3306 in the inbound rules at my cloud provider
This error usually appears when the connection to the sql server is not established. Some things to take care of are :
Ensure mysql server is running in the host you are trying to connect to.
Ensure the host ip is correct.
Ensure that the port entered is correct.
Ensure that the firewall rules are defined correctly.
There could be couple of reasons for this, Listing out a few I have faced,
Remote root access not granted by the mysql server.
The configs are filtered by the environment, Which ideally is done by using the NODE_ENV variable, can you try running your server locally with prod config. In my case, I would do something like NODE_ENV=production node server.js. Assuming server.js is the start file. You can try logging the value's before new Sequelize(...), that might give a better idea as to what's going in.
I was facing the same issue. While in my case I gave a wrong port number (I didn't update my port number for the production database)
I had the same issue and my problem was in the ports. MySql had ports 3306 and in the config, i wrote port 3000 :D
Thanks for helped