Node Sequelize cannot connect to MySQL SSL - mysql

I'm trying to connect my node app to my remote MySQL server and I am getting the following error:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'remoteUser'#'mysqlIpAddress' (using password: YES)
However, I can connect to the mysql server just fine by using the following command.
mysql -u remoteUser -h 138.68.15.94
Here is my connection string
sequelize = new Sequelize(config.mysql.database, config.mysql.user, config.mysql.password, {
host: config.mysql.host,
dialect: 'mysql',
ssl: true,
dialectOptions: {
ssl: true
},
define: {
timestamps: false
},
pool: {
max: 5,
min: 0,
idle: 10000
},
})
Any help would be great! I've been fighting this the past two days.

Related

nodejs sequelize connect to a remote mySQL database always give ETIMEDOUT

i need your help regarding connecting sequelize to a remote mySQL database
sequelize connects fine when i set host attribute to 'localhost' like this:
new Sequelize('billsmanager', 'root', '12345', {
host: `localhost`,
dialect: 'mysql',
define: {
timestamps: false
},
pool: {
max: 25,
min: 0,
idle: 10000
},
})
then i've tried to put my local IP address at home instead of 'localhost' and ETIMEDOUT comes
i tried freeinfinity hosting site it gives ETIMEDOUT
my office server it gives ETIMEDOUT
even i tried my brother's home server and it gives me ETIMEDOUT
and even my network at home it gives ETIMEDOUT
someone suggested here to add inbound rule in firewall for port 3306 and it doesn't work
and commenting bind-address in my.ini didn't work too
i'm using XAMPP
i don't know really why this happens
can you help me?
thanks so much in advance,i really need this to work
i've solved it at last with very silly solution
i added a connect timeout to 100Sec and it worked and connected after like 12Sec
i wrote the initialization like this:
sequelizer: new Sequelize('billsmanager', 'root', '12345', {
host: `192.168.1.2`,
dialect: 'mysql',
dialectOptions: {
connectTimeout:100000
},
define: {
timestamps: false
},
pool: {
max: 25,
min: 0,
idle: 10000
},
}),
thanks

Unable to connect to the database with mySQL

i have created database file
export default {
host: process.env.DB_HOST,
type: 'mysql',
port: process.env.DB_PORT || 3306,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
entities: ['src/**/*.entity{.ts,.js}'],
synchronize: process.env.DB_SYNCRONIZE === 'true',
logging: process.env.DB_LOGGING === 'true',
};
I am getting error :Client does not support authentication protocol requested by server; consider upgrading MySQL client
For MySQL8, Default authentication mechanism has been changed to caching_sha2_password. If your drivers or client doesn't support then Create a new user with mysql_native_password mechanism and use that user in code. Please follow below command to create new user with native password.:
CREATE USER 'nativeuser'#'localhost' IDENTIFIED WITH
mysql_native_password BY 'password';

lando - mysqldump: Got error: 2002: Can't connect to local MySQL server

I am trying to exporting database via lando command which is documented on
https://docs.lando.dev/config/drupal8.html#connecting-to-your-database
lando db-export database_backup.sql
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/opt/bitnami/mysql/tmp/mysql.sock' (111) when trying to connect
Failed to create file: /app/database_backup.sql
Here is lando info
service: 'database',
urls: [],
type: 'mysql',
internal_connection: {
host: 'database',
port: '3306'
},
external_connection: {
host: 'localhost',
port: '32807'
},
creds: {
database: 'drupal8',
password: 'drupal8',
user: 'drupal8'
},
It looks like your MySQL server does not work properly.
lando rebuild
should fix it.

Connect to RDS MySQL programatically (NodeJs, Java) - ER_ACCESS_DENIED_ERROR: Access denied for user

I am trying to connect to my RDS (AWS MySQL database) using NodeJs mysql library.
const mysql = require('mysql');
var connection;
connection = mysql.createConnection({
host: 'xxx.us-east-1.rds.amazonaws.com',
port: 3306,
user: "username",
password: "MyPassword",
database: "DbName",
});
I was also trying mysql2 and sequelize. All of them got me the same result:
{
error: ER_ACCESS_DENIED_ERROR: Access denied for user 'username'#'myhost,
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000'
}
However, this remote database is set to public and I am able to connect to it with mysql command:
mysql -u username -pMyPassowrd -h xxx.us-east-1.rds.amazonaws.com
I am also able to connect to it with MySQL Workbench.
Also, the problem is not in NodeJs, because I am able to connect to my local database:
connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'test',
});
In conclusion, my AWS database is publicly available and I can connect to it, just not using NodeJs for some reason.
I have not found a useful answer yet. Did anyone encounter this problem ?
UPDATE:
Trying to connect in Java with simple Connection returns the same result as well:
final Connection con = DriverManager.getConnection("jdbc:mysql:/xxx.us-east-1.rds.amazonaws.com:3306/DbName", "username", "MyPassword");
UPDATE 2:
I was missing one slash for Java code. I needed to use jdbc:mysql:// instead of jdbc:mysql:/. But NodeJs implementation is still one big mystery.
The answer was rather simple, just add an ssl option with true value
connection = mysql.createConnection({
host: 'xxx.us-east-1.rds.amazonaws.com',
port: 3306,
user: "username",
password: "MyPassword",
database: "DbName",
ssl: true //this does the trick
});

How to connect Node Sequelize to Amazon RDS MySQL with Multi-AZ probably

I'm using an Amazon RDS hosted MySQL with Multi-AZ Support. Just could not find any information on how to connect Sequelize to Amazon RDS properly so that Sequelize is handling fail-overs etc. accordingly?
I'm just using the following config, but do not know if this is enough or recommended?
sequelizeConfig = {
logging: false,
pool: { maxConnections: 5, maxIdleTime: 30},
sequelizeConfig[dialectOptions] = {
ssl: 'Amazon RDS'
}
}
Using Amazon RDS with Multi-AZ I consider the following is important:
Try reconnecting if connection got lost, until it is available again
Don't cache mysql server ip address too long (Amazon suggests less than 1 min)
Amazon Docs are not writing anything about connection handling and pooling.
Here is how i got connected with my RDS:
var config = require(__dirname + '/../config/config.json')[env];
// your config file will be in your directory
var sequelize = new Sequelize(config.database, config.username, config.password, {
host: '****.****.us-west-1.rds.amazonaws.com',
port: 5432,
logging: console.log,
maxConcurrentQueries: 100,
dialect: 'postgres',
dialectOptions: {
ssl:'Amazon RDS'
},
pool: { maxConnections: 5, maxIdleTime: 30},
language: 'en'
})
The previous answer didn't work for me, after some research, this options object did:
var options = {
host: settings.database.host,
port: settings.database.port,
logging: console.log,
maxConcurrentQueries: 100,
dialect: 'mysql',
ssl: 'Amazon RDS',
pool: { maxConnections: 5, maxIdleTime: 30 },
language: 'en',
}
I'm running a RDS MySQL and a EC2 instance in the same default VPC, this options object worked when connecting a node app from that EC2 with the RDS using sequelize.